gitlab ci:手动或仅主控时运行构建作业
是否可以有一个gitlab ci文件,其中定义了具有以下要求的构建作业:gitlab ci:手动或仅主控时运行构建作业,gitlab,jobs,gitlab-ci,Gitlab,Jobs,Gitlab Ci,是否可以有一个gitlab ci文件,其中定义了具有以下要求的构建作业: 手动时执行 或 通过主推执行 我想到过这样的事情,但这是错误的: build_jar: stage: build script: - echo "build jar" artifacts: paths: - jar/path/*.jar only: - master when: manual 对我来说,唯一的解决办法是有两个工作,一个是主推,另一个是手动输入。但缺点是,在gitlab中,它变得令人
- 手动时执行 或
- 通过主推执行
build_jar:
stage: build
script:
- echo "build jar"
artifacts:
paths:
- jar/path/*.jar
only:
- master
when: manual
对我来说,唯一的解决办法是有两个工作,一个是主推,另一个是手动输入。但缺点是,在gitlab中,它变得令人困惑您想要的确切内容目前是不可能的。虽然这两个作业(一个只有
的作业:master
,另一个只有的作业:when:manual
)应该提供一个替代方案
如果你把它们放在同一个阶段,我想应该不会那么混乱
你也可以使用一些类似的方法来停留。我也没有在一个区块中找到这样做的方法,只能使用yaml锚,并将其分为两个单独的区块:
.deploy_common:
# common config HERE
deploy_master_CD:
extends: .deploy_common
only:
refs:
- master
deploy_manual:
extends: .deploy_common
when: manual
还是GitLab 12.3之后的一体机
我自己也遇到过这个问题,最终解决了(或者为我的需求找到了一个可行的版本): 变量块下的条件是“或”组合在一起的,因此当作业在主分支上或从web启动时(在我的情况下,可与“手动”互换)会运行该作业。这不会像“when:manual”那样暂停管道,但无论如何我都不希望它这样做 这是文件:和
希望这会有所帮助!在GitLab 11.3中定义两个作业会变得更容易。它是使用YAML锚的一种替代方法,并且更加灵活易读:
.deploy_common:
# common config
deploy_master_CD:
extends: .deploy_common
only:
refs:
- master
deploy_manual:
extends: .deploy_common
when: manual
我不得不使用它来避免产生额外的“阻塞”管道
- if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"' # Avoid spawning of additional pipelines
when: never
- if: '$CI_MERGE_REQUEST_ID != ""' # Force manual deploy if master was pushed without a MR
when: manual
allow_failure: true # to avoid blocked state for the whole pipeline
- if: '$CI_COMMIT_REF_SLUG == "master"' # Auto deploy on master
when: on_success
- when: manual # Manually deploy on all other branches
allow_failure: true # to avoid blocked state for the whole pipeline
我认为这是行不通的:在gitlab 11.6.8中,我试图创建一个未命名为“master”的分支,该作业在web UI中不可见,但对于名为“master”的分支,它变为可见。因此我猜
$CI\u PIPELINE\u SOURCE==“web”
不足以使作业在web UI中可见。Rely nice,感谢您提出此解决方案!现在应该是公认的答案!据我所知,没有直接的规则-当:手动在规则下时,如果我错了,请纠正我,但从文档和当:手动操作没有o直接在作业名称下,或(自12.3起)在if
规则下。这些规则为我产生了奇怪的二级“阻塞”管道。
.deploy_common:
# common config
deploy_master_CD:
extends: .deploy_common
only:
refs:
- master
deploy_manual:
extends: .deploy_common
when: manual
- if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"' # Avoid spawning of additional pipelines
when: never
- if: '$CI_MERGE_REQUEST_ID != ""' # Force manual deploy if master was pushed without a MR
when: manual
allow_failure: true # to avoid blocked state for the whole pipeline
- if: '$CI_COMMIT_REF_SLUG == "master"' # Auto deploy on master
when: on_success
- when: manual # Manually deploy on all other branches
allow_failure: true # to avoid blocked state for the whole pipeline