【问题标题】:Use pushed branch name in gitlab-ci script在 gitlab-ci 脚本中使用推送的分支名称
【发布时间】:2022-01-06 04:56:29
【问题描述】:

我有这个 gitlab-ci 脚本,它在带有前缀 staging- 的分支上运行,使用正则表达式和脚本中的命令签出到推送的分支。如何在脚本中使用推送的分支名称?我尝试使用相同的正则表达式,但作业失败了。

deploy:
  tags:
    - server
  only:
    - /^staging-.*$/
  script:
    - cd /var/www/project
    - sudo git reset --hard HEAD
    - sudo git clean -fd
    - sudo git checkout /^staging-.*$/
    - sudo git pull origin /^staging-.*$/

【问题讨论】:

    标签: gitlab gitlab-ci


    【解决方案1】:

    在阅读了一些 Gitlab 文档后,我发现使用预定义变量效果最好。

    来源:https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

    deploy:
      tags:
        - server
      only:
        - /^staging-.*$/
      script:
        - cd /var/www/project
        - sudo git reset --hard HEAD
        - sudo git clean -fd
        - sudo git checkout ${CI_COMMIT_BRANCH}
        - sudo git pull origin ${CI_COMMIT_BRANCH}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 2015-03-08
      • 2020-10-27
      • 2022-01-10
      相关资源
      最近更新 更多