Gitlab script conditionally

There are 3 steps in .gitlab-ci.yml - assembly, testing and deployment.

A nightly regression test should be done - well nightly :)

Here is the corresponding .gitlab-ci.yml code:

 stages: - build - test - deploy build_project: stage: build script: - cd ./some-dir - build-script.sh except: - tags #Run this only when say variable 'NIGHTLY_TEST == True'. But HOW? nightly_regression_test_project: stage: test script: - cd ./some-dir - execute test-script 

Marking daily only run test events is not preferred.

Any other idea?

+19
source share
5 answers

In case someone is looking for this now, gitlab has now implemented a scheduled build function with rewriting variables (incredibly convenient). Documentation found here .

For those who are interested in the instructions for this function, when this answer was given, here it is:

Using pipelined schedules

To schedule a pipeline:

  1. Go to your project Conveyors → Schedules and click the New Schedule button.
  2. Fill the form
  3. Click Save Pipeline Schedule for the changes to take effect.

My favorite feature is the scheduled pipeline variables.

The variable documentation can be found here , but the most useful information for me was the priority that I will rewrite here:

Variable Priority

Variables can be overwritten, and they take precedence over each other in the following order:

  1. Variables or scheduled pipeline variables (take precedence over all)
  2. Project-level secret variables or protected secret variables
  3. Group-level secret variables or protected secret variables
  4. YAML Defined Job Level Variables
  5. YAML Defined Global Variables
  6. Deployment variables
  7. Predefined variables (lowest in the chain)

Hope this helps. I'm glad they added this feature.

+7
source

except and only can indicate the variables that will run them.

You can use the following in your .gitlab-ci.yml:

 build1: stage: build script: - echo "Only when NIGHTLY_TEST is false" except: variables: - $NIGHTLY_TEST test1: stage: test script: - echo "Only when NIGHTLY_TEST is true" only: variables: - $NIGHTLY_TEST 
+21
source

There is currently no way to run a task depending on environment variables (you can always open a function request!). You can use the simple Bash command to exit immediately if the environment variable does not exist.

Sort of:

 stages: - build - test - deploy build_project: stage: build script: - cd ./some-dir - build-script.sh except: - tags # Run this only when NIGHTLY_TEST environment variable exists. nightly_regression_test_project: stage: test script: - [ -z "$NIGHTLY_TEST" ] && exit 1; - cd ./some-dir - execute test-script 

If the variable does not exist, subsequent tests will not be performed. Otherwise they will.

Hope this helps!

+13
source

I need to build my production only on a superior master and only on tags. Can someone help me with this?

0
source

I just implemented this “function”, following the example here. Use crontab and curl (I use Linux because why not?) To set up a trigger to run your nightly tests.

 30 0 * * * curl --request POST --form token=TOKEN --form ref=master https://gitlab.example.com/api/v3/projects/9/trigger/builds 
-2
source

Source: https://habr.com/ru/post/1258056/


All Articles