Reputation: 1941
Hello I am new to gitlab, and so far i succeded in doing everything (runners, pipelines, etc...)
But I now want to set automatic tests build only once per day, triggered by a CRON but NOT TRIGGERED by each push made on the git repo.
I am using a 8.14.2 gitlab without the new SCHEDULE feature
So I used this gitlab.ci.yml:
stages:
- test
test-karma:
stage: test
image: node:8.9.4
before_script:
- apt-get update
- apt-get --yes install npm
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- npm install @angular/[email protected]
- npm install
environment: dev
script:
- ./node_modules/.bin/ng test --single-run=true --watch=false
only:
- triggers
except:
- pushes
But despite the only / except part, the job is triggered :
() For each git push (which i don't want)
() By the CRON which I want
So I found another way
1- Set a variable SHOULD_EXECUTE to false on gitlab
2- Protect every script line by an if statement
3- Use the following CRON:
00 4 * * * curl -X POST -F token=MY_TOKEN -F ref=master -F "variables[SOULD_EXECUTE]=true" http://MY_GITLAB_URL/api/v3/projects/30/trigger/builds
4- And changed the gitlab.ci.yml to
stages:
- test
test-karma:
stage: test
image: node:8.9.4
before_script:
- if [ ${SOULD_EXECUTE} == "true" ]; then apt-get update;fi
- if [ ${SOULD_EXECUTE} == "true" ]; then apt-get --yes install npm ;fi
- if [ ${SOULD_EXECUTE} == "true" ]; then apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget;fi
- if [ ${SOULD_EXECUTE} == "true" ]; then npm install @angular/[email protected];fi
- if [ ${SOULD_EXECUTE} == "true" ]; then npm install; else echo "TEST JOB SKIPPED";fi
- echo 'SOULD_EXECUTE => ' + ${SOULD_EXECUTE}
environment: dev
script:
- if [ ${SOULD_EXECUTE} == "true" ]; then ./node_modules/.bin/ng test --single-run=true --watch=false;fi
only:
- triggers
It's Ugly... Could some one help me to set this up ? Thank you so much.
regards.
Upvotes: 0
Views: 2947
Reputation: 1941
I fixed my issue without knowing how or why. I had to move the repo to another group in gitlab. And now it's working perfectly, the only : triggers (without except : pushes) enable me to NOT run a pipeline for each pushes, and I can run this with the CRON post call.
Upvotes: 0