GitLab ci CD删除合并请求的项目 [英] Gitlab ci cd removes artifact for merge requests
本文介绍了GitLab ci CD删除合并请求的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的GitLab ci CD管道中,我有两份工作:
- Build:此作业将在创建从开发分支到发布分支的拉取请求后触发。我将生成我的项目分发(vuejs项目),生成作为环境变量的版本(版本将从目标分支名称检索)。如果目标为Release/1.0.0,则版本将为1.0.0)
- 发布:此作业将获取工件并基于其创建docker图像。上一作业中创建的版本将是图像标记。
build:
image: node:15.5.1-alpine3.10
stage: build
before_script:
# retrieve the new version from the branch name
- version="$(echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME | cut -d '/' -f 2)"
- echo "The new version to release is $version"
script:
- npm install -g @vue/cli
- npm install
- npm run build
# write the version to the build.env so it can be used in the next jobs
- echo "BUILD_VERSION=$version" >> build.env
- cat build.env
artifacts:
when: on_success
paths:
- dist
reports:
dotenv: build.env
# Run this job only when merge request on release and master branches
rules:
- if: ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^release/d+.d+.d+$/) && ($CI_PIPELINE_SOURCE == "merge_request_event")
正如我们在下面看到的,已经生成了version build_version环境变量。
publish:quality:
stage: publish
image: docker:19.03.12
services:
- docker:19.03.12-dind
variables:
CI_REGISTRY_IMAGE: 'mouhamedali/co-training-gui'
before_script:
- echo " The build version is $BUILD_VERSION"
- docker login --username mouhamedali --password-stdin < $GITLAB_DOCKER_HUB_TOKEN
script:
- docker pull $CI_REGISTRY_IMAGE || true
- echo "Building the docker image $CI_REGISTRY_IMAGE:$BUILD_VERSION"
- docker build --cache-from "$CI_REGISTRY_IMAGE" -t "$CI_REGISTRY_IMAGE:$BUILD_VERSION" .
- docker push $CI_REGISTRY_IMAGE:$BUILD_VERSION
dependencies:
# get artifacts only from the build job
- build
only:
- /^release/d+.d+.d+$/
但是在发布的下一个作业中,build_version为空。
如果我将生成作业的规则更改为在将开发合并到发布之后触发,则它工作正常,并且如果我将规则更改为MERGE_REQUESTS,则版本存在但不存在,因此我不知道为什么它在第二种情况下不起作用。
ci-CD文件:https://gitlab.com/co-training/co-training-gui/-/blob/develop/.gitlab-ci.yml
推荐答案
artifacts:reports:dotenv
不支持与dependencies:
/needs:
一起使用。
您可以看到this issue哪些需要更好地记录(注释中有关此特定案例的详细信息)
我发现最好将.env
文件作为普通项目生成,然后在后续作业中生成source
文件。
build:
#...
artifacts:
paths:
- build.env
release:
before_script:
- source build.env
这篇关于GitLab ci CD删除合并请求的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文