我想要使用Gitlab搭建CI/CD流水线,以下是我的需求:
注意:我的项目是Typescript
- 执行单元测试和集成测试
- 将dev分支推进到integration分支
- 从integration分支构建Docker镜像
- 部署到integration环境中
以下是我正在使用的.gitlab-ci.yml
:
stages:
- test
- promote
- build
- deploy
cache:
paths:
- node_modules/
test:
image: node
stage: test
before_script:
- yarn
script:
- yarn test
promote:
image: node
stage: promote
only:
- dev
script:
- git push origin HEAD:integration
build
image: node
stage: build
only:
- integration
script:
- echo "build docker image from integration"
deploy:
image: node
stage: deploy
only:
- integration
script:
- echo "deploy integration"
我的问题是,这行代码 git push origin HEAD:integration
无法在GitLab Runner上执行,以下是控制台输出:
Running with gitlab-runner 10.1.0 (c1ecf97f)
on RUNNER (ce8757c9)
Using Docker executor with image node ...
Using docker image sha256:fb8322a7cefdf2b3ba1c15218187bb65f9d4d4ab4e27dc3a91bb4eba38964429 for predefined container...
Pulling docker image node ...
Using docker image node ID=sha256:c1d02ac1d9b4de08d3a39fdacde10427d1c4d8505172d31dd2b4ef78048559f8 for build container...
Running on runner-ce8757c9-project-907-concurrent-0 via VERD842...
Fetching changes...
Removing node_modules/
HEAD is now at 63cccc5 update ci - dev
From https://gitlab.mycompany.com/project1/ci-demo
63cccc5..98d347e dev -> origin/dev
Checking out 98d347e5 as dev...
Skipping Git submodules setup
Checking cache for default...
Successfully extracted cache
$ git push origin HEAD:integration
remote: You are not allowed to upload code for this project.
fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mycompany.com/project1/ci-democi-demo.git/': The requested URL returned error: 403
ERROR: Job failed: exit code 1
我已经阅读了文档和一些示例,但是我无法弄清楚如何使其工作?
我应该创建一个名为gitlab-ci-token
的用户吗?
我应该在bash
脚本中进行分支推广吗?
欢迎随时给我任何有关我尝试实现的流水线的反馈意见...
此致敬礼