gitlab - 如何手动触发Gitlab CI管道,在正常情况下,它是由带有commit Ids的webhook触发的?

标签 gitlab gitlab-ci gitlab-ci-runner gitlab-ce

我有 Gitlab CI 管道,它由带有当前和最后提交 ID 的 bitbucket webhook 触发。我还想在由 webhook 触发的构建创建的 Gitlab CI 文件未按预期工作时手动重新运行管道。 我尝试了 RUN-PIPELINE 选项但显示错误:

表单包含以下错误: 此管道没有阶段/作业。 enter image description here

这是 GitLab CI 文件。 Include 指的是保存管道标准 yaml 文件的其他项目:

include:
- project: Path/to/project
  ref: bb-deployment
  file: /bitbucket-deployment.yaml
variables:
  TILLER_NAMESPACE: <namespace>
  NAMESPACE: testenv
  REPO_REF: testenvbranch
  LastCommitSHA: <commit sha from webhook>
  CurrentCommitSHA: <Current commit she from webhook>

这是其他具有阶段的项目中提供的详细 gitlab-ci 文件:

stages:
  - pipeline
  - build

variables:
    ORG: test
    APP_NAME: $CI_PROJECT_NAME

before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIIVATE_KEY2" | tr -d '\r' | ssh-add -
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts


Building CI Script:
  stage: pipeline
  image: python:3.6
  only:
    refs:
      - master
  script:
    - |
      curl https://github.com/org/scripts/branch/install.sh | bash -s latest
      source /usr/local/bin/pipeline-variables.sh
      git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dabdb3ae9ab8b3aeb8afb9b1bfaef4b5a8bd" rel="noreferrer noopener nofollow">[email protected]</a>:$ORG/$APP_NAME.git
      cd $APP_NAME
      git checkout $lastCommit
      cp -r env old
      git checkout $bitbucketCommit
      $CMD_DIFF old env
      $CMD_BUILD
      $CMD_INSTALL updatedReposList.yaml deletedReposList.yaml /tmp/test $NAMESPACE $REPO_REF $ORG $APP_NAME $lastCommit $bitbucketCommit
      cat cicd.yaml
      mv cicd.yaml ..

  artifacts:
    paths:
      - cicd.yaml

Deplopying Apps:
  stage: build
  only:
    refs:
      - master
  trigger:
    include:
      artifact: cicd.yaml
      job: Building CI Script
    strategy: depend

在手动触发器中,不应考虑上次和当前的提交,而应重建应用程序。

任何帮助将不胜感激。

最佳答案

感谢您的评论(如下),我看到您在一个 .gitlab-ci.yml 中使用 include 指令 ( https://docs.gitlab.com/ce/ci/yaml/#include ) 来包含来自另一个项目的 GitLab CI YAML 文件。

当项目 2 GitLab CI YAML 仅限于 master 分支,但我正在另一个 分支上运行该项目。

例如,假设项目 1 名为“stackoverflow-test”,其 .gitlab-ci.yml 为:

include:
- project: atsaloli/test
  file: /.gitlab-ci.yml
  ref: mybranch

项目 2 称为“test”(在我自己的命名空间中,atsaloli),其 .gitlab-ci.yml 是:

my_job:
  script: echo hello world
  image: alpine
  only:
    refs:
      - master

如果我在“master”以外的分支上的项目 1 的 GitLab UI 中选择“运行管道”,则会收到错误消息“此管道没有阶段/作业”。

那是因为我的非主分支没有定义作业,如果没有定义任何作业,我就没有定义任何阶段。

我希望这能让您了解您的 webhook 的情况。

关于gitlab - 如何手动触发Gitlab CI管道,在正常情况下,它是由带有commit Ids的webhook触发的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61197429/

相关文章:

gitlab - 限制对 gitlab 容器注册表的访问

node.js - Gitlab-ci 没有使用我指定的 Node 版本

gitlab - 如何获取: merge_request_iid if know CI_BUILD_ID and CI_PROJECT_ID?

gitlab - 当我将执行器设置为 shell 时,为什么 gitlab-runner 作为 ruby​​ docker 运行执行?

即使测试失败,Gitlab runner 也不会失败

gitlab - 更改 gitlab runner 的克隆目录

gitlab - 在 gitlab-ci.yml 上动态设置工件路径/文件夹结构

apache - 422 不可处理的实体,JS 文件,gitlab 8.17,apache ssl

powershell - 无法在 Gitlab CI/CD yaml 中转义冒号

docker - 不要在 gitlab-ci 中的不同架构之间共享工件