Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test gitlab-ci.yml?

Tags:

gitlab-ci

I've finally manage to make it work so that when you push to a branch job would launch, but I keep waiting for it to launch around 3min and then I've got errors which I need to fix and then commit again, and then waiting again. How can I just ssh to that public runner and test .gitlab-ci.yml "script" part just in the bash?

like image 608
holms Avatar asked Mar 04 '18 00:03

holms


People also ask

Can I test GitLab CI locally?

In the above gitlab-ci. yml build job will run the scripts under build_job then test_job will execute the test scripts under test_job and so on with the package and deploy stages. Gitlab-runner exec is the command that helps us test locally. The exec command should be executed directly from the root directory because .


1 Answers

For the record: You can also copy paste your gitlab-ci.yml into the linter-form provided by gitlab:

enter image description here

Depending on which IDE you are using you might be able to find plugins that check for validity. For example in VS Code you can use a plugin called gitlab-vscode-extension which can validate your .gitlab-ci.yml file.

In case you want to programatically validate your .gitlab-ci.yml, gitlab provides an API which allows you to POST your yml to /ci/lint, e.g.:

curl --header "Content-Type: application/json" https://gitlab.example.com/api/v4/ci/lint --data '{"content": "{ \"image\": \"ruby:2.6\", \"services\": [\"postgres\"], \"before_script\": [\"bundle install\", \"bundle exec rake db:create\"], \"variables\": {\"DB_NAME\": \"postgres\"}, \"types\": [\"test\", \"deploy\", \"notify\"], \"rspec\": { \"script\": \"rake spec\", \"tags\": [\"ruby\", \"postgres\"], \"only\": [\"branches\"]}}"}' 
like image 93
B12Toaster Avatar answered Sep 30 '22 15:09

B12Toaster