3

https://github.com/researchgate/gradle-release在 Gitlab 上的 ci 中使用以下配置:

release:
image: gradle:jdk11
stage: release
script:
 - git checkout master
 - ./gradlew release
only:
 - master
when: manual

它抱怨用户无权写入回购。

Execution failed for task ':example-core:preTagCommit'.
> Failed to push to remote - [][remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab.com/myUser/example.git/': The 
requested URL returned error: 403

我检查了 CI Job Token 只有读取权限。有没有办法在这里登录作为脚本的一部分,理想情况下使用令牌而不是硬编码凭据?谢谢。

编辑一: 我尝试使用具有以下配置的 SSH 密钥/部署密钥。但它没有用:

release:
image: gradle:jdk11
stage: release
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client - 
y )'

- eval $(ssh-agent -s)
- ssh-add <(echo "$CI_CD_SSH_KEY")
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- git config --global user.email "myUserg@gmail.com"
- git config --global user.name "GitLab CI/CD"
- git checkout -B master
- ./gradlew release -DskipTests

编辑二: 我在这里添加了正确的配置。诀窍是在将 SSH 密钥添加到正确的位置和 SSH 代理后检查 repo:

release:
image: gradle:jdk11
stage: ...
before_script:
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)

# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- echo "$CI_CD_SSH_KEY" | tr -d '\r' | ssh-add -


- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
 # copy the keys to the right place
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "username@gmail.com"
- git config --global user.name "GitLab CI/CD"
- git remote set-url origin git@gitlab.com:username/project.git
- git checkout master
# grab the version from the properties file
- VERSION=`grep 'version' ./gradle.properties | grep -oE "(([0-9]{1,3}\.){2} 
[0-9]{1,3})"`

在此之后,您可以像这样运行您的脚本:

  script:
- ./gradlew release
4

0 回答 0