gitlab-ci,如何防止从跑步者推入时发生其他触发

时间:2019-02-20 03:34:40

标签: gitlab-ci gitlab-ci-runner

这是管道的工作方式

  • 在推动主工作(按预期工作)时:构建项目&&将jar推送至开发人员
  • 创建标签时(无法按预期工作):

    1. 构建项目
    2. 增加pom.xml的版本并将pom.xml推送到
    3. 将jar推送到服务器

但是当我执行步骤2时,它会在CI中重新触发另一个版本。

在这种情况下,如何推动并避免触发作业?

这是完整的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 "gitlab-ci@unc.nc"
    - 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"

1 个答案:

答案 0 :(得分:1)

我在提交消息中有字符串“ [ci skip]”,它可以正常工作:

  • git commit -m“增加pom版本[ci skip]”