Tyvain
Tyvain

Reputation: 2760

gitlab-ci, how to prevent another trigger when pushing from a runner

Here is how the pipeline works

But when I do step 2, it retrigger another build in the CI.

How can I push and avoid triggering the job in this case ?

Here is the full gitlab-ci.yml:

image: maven:3.6.0-jdk-10

variables:
  APP_NAME: demo
  MAVEN_OPTS: -Dmaven.repo.local=/cache/maven.repository

stages:
- build
- deploy_dev
- deploy_prod

build:
  stage: build
  script:
  - mvn package -P build
  - mv target/*.jar target/$APP_NAME.jar
  artifacts:
    untracked: true

deploy_dev:
  before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - '[[ -f /.dockerenv ]] && mkdir -p ~/.ssh && echo "$KNOWN_HOST" > ~/.ssh/known_hosts'
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  stage: deploy_dev
  environment:
    name: dev
    url: http://devsb01:9999
  dependencies:
  - build
  only:
  - master
  except:
  - tags
  script:
  - ssh root@devsb01 "service $APP_NAME stop"
  - scp target/$APP_NAME.jar root@devsb01:/var/apps/$APP_NAME/
  - ssh root@devsb01 "service $APP_NAME start"

deploy_prod:
  before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - '[[ -f /.dockerenv ]] && mkdir -p ~/.ssh && echo "$KNOWN_HOST" > ~/.ssh/known_hosts'
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  stage: deploy_prod
  environment:
    name: production
  dependencies:
  - build
  only:
  - tags
  except:
  - branches
  script:
    - mvn versions:set -DnewVersion=$CI_COMMIT_REF_NAME
    - git config --global user.name "gitlab-ci"
    - git config --global user.email "[email protected]"
    - git --version
    - git status
    - git add pom.xml
    - git commit -m "increment pom version"
    - git push http://gitlab-ci:${GITLABCI_PWD}@gitlab.unc.nc/dsi-infogestion/demo.git HEAD:master
    - git status
    - ssh root@prodsb01 "service $APP_NAME stop"
    - scp target/$APP_NAME.jar root@prodsb01:/var/apps/$APP_NAME/
    - ssh root@prodsb01 "service $APP_NAME start"

Upvotes: 2

Views: 1490

Answers (1)

Tyvain
Tyvain

Reputation: 2760

I had the string '[ci skip]' in the commit message and it works:

  • git commit -m "increment pom version [ci skip]"

Upvotes: 3

Related Questions