gitlab-ci-local
gitlab-ci-local copied to clipboard
Tired of pushing to test your .gitlab-ci.yml?
Tired of pushing to test your .gitlab-ci.yml?
Run gitlab pipelines locally as shell executor or docker executor.
Get rid of all those dev specific shell scripts and make files.
Table of contents
-
Examples
- docker-compose-nodejs
- docker-swarm-php
- Installation
-
Convenience
- CLI options via shell
- DotEnv file
- Bash alias
- Tab completion
-
Quirks
- Tracked Files
- Local Only
- Home File Variables
- Remote File Variables
- Project File Variables
- Decorators
- Includes
- Artifacts
-
Development
- Scripts
- Package binaries
Installation
NPM
npm install -g gitlab-ci-local
Linux based on Debian
curl -s "https://firecow.github.io/gitlab-ci-local/ppa/pubkey.gpg" | sudo apt-key add -
sudo curl -s -o /etc/apt/sources.list.d/gitlab-ci-local.list "https://firecow.github.io/gitlab-ci-local/ppa/gitlab-ci-local.list"
sudo apt-get update
sudo apt-get install gitlab-ci-local
Macos
bash version must be above or equal 4.x.x
brew install gitlab-ci-local
Windows (Git bash)
Install gitbash
Download and put binary in C:\Program Files\Git\mingw64\bin
curl -L https://github.com/firecow/gitlab-ci-local/releases/latest/download/win.gz | gunzip -c > /c/Program\ Files/Git/mingw64/bin/gitlab-ci-local.exe
Convenience
CLI options via shell
# Overrides .gitlab-ci.yml as the default git ci/cd file
export GCL_NEEDS='true' >> ~/.bashrc
export GCL_FILE='.gitlab-ci-local.yml' >> ~/.bashrc
export GLC_VARIABLES="IMAGE=someimage SOMEOTHERIMAGE=someotherimage"
DotEnv file
Add a .gitlab-ci-local-env
file to the current working directory or a .env
file in $HOME/.gitlab-ci-local
# Overrides .gitlab-ci.yml as the default git ci/cd file
FILE=doctor-strange.yml # --file
# Always runs needed jobs, when gitlab-ci-local <job-name> is called
NEEDS=true # --needs
All cli options can be assigned default values this way
Bash alias
echo "alias gcl='gitlab-ci-local'" >> ~/.bashrc
Tab completion
gitlab-ci-local --completion >> ~/.bashrc
Quirks
Tracked Files
Untracked and ignored files will not be synced inside isolated jobs, only tracked files are synced.
Remember git add
Local Only
local-only-job:
rules:
- { if: $GITLAB_CI == 'false' }
local-only-subsection:
script:
- if [ $GITLAB_CI == 'false' ]; then eslint . --fix; fi
- eslint .
Home file variables
Put a file like this in $HOME/.gitlab-ci-local/variables.yml
---
project:
gitlab.com/test-group/test-project.git:
# Will be type Variable and only available if remote is exact match
AUTHORIZATION_PASSWORD: djwqiod910321
gitlab.com:project/test-group/test-project.git: # another syntax
AUTHORIZATION_PASSWORD: djwqiod910321
group:
gitlab.com/test-group/:
# Will be type Variable and only available for remotes that include group named 'test-group'
DOCKER_LOGIN_PASSWORD: dij3213n123n12in3
global:
# Will be type File, because value is a file path
KNOWN_HOSTS: '~/.ssh/known_hosts'
DEPLOY_ENV_SPECIFIC:
type: variable # Optional and defaults to variable
values:
'*production*': 'Im production only value'
'staging': 'Im staging only value'
FILE_CONTENT_IN_VALLUES:
type: file
values:
'*': |
Im staging only value
I'm great for certs n' stuff
Variables will now appear in your jobs, if project or group matches git remote, global's are always present
Remote file variables
gitlab-ci-local --remote-variables [email protected]:firecow/example.git=gitlab-variables.yml=master
Project file variables
Put a file like this in $CWD/.gitlab-ci-local-variables.yml
---
AUTHORIZATION_PASSWORD: djwqiod910321
DOCKER_LOGIN_PASSWORD: dij3213n123n12in3
# Will be type File, because value is a file path
KNOWN_HOSTS: '~/.ssh/known_hosts'
Variables will now appear in your jobs.
Decorators
The @Description
decorator
Adds descriptive text to gitlab-ci-local --list
# @Description Install npm packages
npm-install:
image: node
artifacts:
paths:
- node_modules/
script:
- npm install --no-audit
The @Interactive
decorator
# @Interactive
interactive-shell:
rules:
- if: $GITLAB_CI == 'false'
when: manual
script:
- docker run -it debian bash
The @InjectSSHAgent
decorator
# @InjectSSHAgent
need-ssh:
image: kroniak/ssh-client
script:
- ssh-add -L
The @NoArtifactsToSource
decorator
Prevent artifacts from being copied to source folder
# @NoArtifactsToSource
produce:
stage: build
script: mkdir -p path/ && touch path/file1
artifacts: { paths: [path/] }
A global configuration is possible when setting the following flag
gitlab-ci-local --no-artifacts-to-source
Includes
Includes from external sources are only fetched once. Use --fetch-includes
to invoke an external fetching rutine.
Artifacts
Shell executor jobs copies artifacts to host/cwd directory. Use --shell-isolation option to mimic correct artifact handling for shell jobs.
Docker executor copies artifacts to and from .gitlab-ci-local/artifacts
Development
You need nodejs 18+
Scripts
npm install
npm run build
npm run test
Package binaries
npm run pkg-linux
npm run pkg-win
npm run pkg-macos
npm run pkg-all