与我的同事们一起,我们开发了一个C++库,这个库每天变得越来越重要。我们已经通过gitlab-ci.yml文件构建了连续集成实用程序,该文件允许我们:
所有让我们选择GitLab的东西!
我们希望对我们的整个库进行概要分析,并在一个单独的项目中推进基准测试。我们已经使用SSH密钥方法为out文档做了一些工作,但是这次我们想避免这样做。
我们试过这样的脚本:
test_ci_push:
tags:
- linux
- shell
- light
stage: profiling
allow_failure: false
only:
- new-benchmark-stage
script:
- git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git &> /dev/null
- cd benchmarks
- touch test.dat
- echo "This is a test" > test.dat
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git add --all
- git commit -m "GitLab Runner Push"
- git push http://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git HEAD:master
- cd ..我们还尝试了一个基本的git push origin master来推送更新的文件,但是每次我们得到相同的答案:
remote: You are not allowed to upload code for this project.
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mycompany.home/developers/benchmarks.git/': The requested URL returned error: 403这两个项目都在同一个site下,我有权利推进这两个项目。我在哪里做错事了?
发布于 2017-09-29 07:53:58
gitlab令牌更像github.com中的部署密钥,因此它只具有对存储库的读取访问权限。要真正推动,您将需要生成一个个人访问令牌,并使用它。
首先,您需要生成令牌,如所示在gitlab文档中所示。确保同时检查read和api作用域。而且,这只适用于GitLab 8.15和更高版本。如果您使用的是旧版本,并且不希望升级,我可以向您展示另一种方法,但它更复杂,安全性更低。
最后,您的gitlab-ci.yml应该是这样的:
test_ci_push:
tags:
- linux
- shell
- light
stage: profiling
allow_failure: false
only:
- new-benchmark-stage
script:
- git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git &> /dev/null
- cd benchmarks
- echo "This is a test" > test.dat
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git add --all
- git commit -m "GitLab Runner Push"
- git push http://${YOUR_USERNAME}:${PERSONAL_ACCESS_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git HEAD:master
- cd ..发布于 2019-03-25 19:02:27
虽然前面的答案或多或少都很好,但也有一些重要的gotya。
before_script:
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
script:
- <do things>
- git push "https://${GITLAB_USER_LOGIN}:${CI_GIT_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_COMMIT_TAG}"首先,我们只需要设置用户名/电子邮件来满足git。
其次,在前脚本中使用它并不是非常关键,但是在执行“扩展”时可以更容易地重用。
最后,推动https是“好的”,但是由于我们没有使用存储的ssh密钥,我们应该避免任何可能显示令牌的东西。首先,虽然gitlab不会在这个命令中打印令牌,但是git会很高兴地通知我们,新的上游被设置为https://username:thetokeninplaintexthere@url,所以这里有纯文本的令牌,所以不要使用-u设置上游。
而且,这是不需要的,我们只是做了一个推动。
此外,在确定URL时,我发现使用exist CI_REPOSITORY_URL是最可靠的解决方案(例如,移动repo或诸如此类)。因此,我们只需替换URL字符串中的用户名/令牌即可。
发布于 2018-05-17 08:46:05
您还可以提供用户和密码(具有写访问权限的用户)作为秘密变量,并使用它们。
示例:
before_script:
- git remote set-url origin https://$GIT_CI_USER:$GIT_CI_PASS@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git config --global user.email 'myuser@mydomain.com'
- git config --global user.name 'MyUser'您必须将GIT_CI_USER和GIT_CI_PASS定义为秘密变量(可以为此目的始终创建专用用户)。
使用此配置,您通常可以使用git。我正在使用这种方法在发布后推送标签(使用Axion发布Gradle Pluing - http://axion-release-plugin.readthedocs.io/en/latest/index.html)
示例发布作业:
release:
stage: release
script:
- git branch
- gradle release -Prelease.disableChecks -Prelease.pushTagsOnly
- git push --tags
only:
- masterhttps://stackoverflow.com/questions/46472250
复制相似问题