Ven*_*kat 19 gitlab gitlab-ci gitlab-ci-runner
我正在使用gitlab CI runner来测试我的代码并生成一些文件.我只是想通过CI runner将生成的文件推送到gitlab存储库.有没有办法做到这一点?
jmu*_*ire 18
我通过这样做解决了这个问题:
User Settings > Access TokensYour project > Settings > Secret variable- > edit:如果要将git push推送到非受保护的分支,请不要将runner变量设置为protected
然后,您可以在gitlab-ci脚本中使用此标记而不是默认标记.例如 :
before_script:
- git remote set-url origin https://USERNAME:${CI_PUSH_TOKEN}@gitlab.com/your-project.git
- git config --global user.email 'your@email.com'
- git config --global user.name 'yourname'
...
- git checkout -B branch
- change files
- git commit -m '[skip ci] commit from CI runner'
- git push --follow-tags origin branch
Run Code Online (Sandbox Code Playgroud)
在gitlab中生成SSH密钥
- >配置文件设置 - > SSH密钥 - >生成它
生成SSH密钥存储后,在名为SSH的gitlab 变量中
- >项目设置 - >变量 - >添加变量
在.gitlab-ci.yml中添加以下行.
before_script:
- mkdir -p ~/.ssh
- echo "$SSH" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H 'Git_Domain' >> ~/.ssh/known_hosts
Run Code Online (Sandbox Code Playgroud)
之后使用下面的js代码将文件推送到存储库.
var child_process = require("child_process");
child_process.execSync("git checkout -B 'Your_Branch'");
child_process.execSync("git remote set-url origin Your_Repository_Git_Url");
child_process.execSync("git config --global user.email 'Your_Email_ID'");
child_process.execSync("git config --global user.name 'Your_User_Name'");
for (var i=0;i<filesToBeAdded.length;i++) {
child_process.execSync("git add "+filesToBeAdded[i]);
}
var ciLog = child_process.execSync("git commit -m '[skip ci]Automated commit for CI'");
var pushLog = child_process.execSync("git push origin Your_Branch");
Run Code Online (Sandbox Code Playgroud)
[skip ci]在提交消息中最重要.否则它将启动CI过程的无限循环.
您当然可以使用 SSH 密钥,但您也可以提供用户和密码(具有写入权限的用户)作为秘密变量并使用它们。
例子:
before_script:
- git remote set-url origin https://$GIT_CI_USER:$GIT_CI_PASS@gitlab.com/$CI_PROJECT_PATH.git
- git config --global user.email 'myuser@mydomain.com'
- git config --global user.name 'MyUser'
Run Code Online (Sandbox Code Playgroud)
您必须将GIT_CI_USER和定义GIT_CI_PASS为秘密变量(您始终可以为此目的创建专用用户)。
通过此配置,您可以正常使用 git。我正在使用这种方法在发布后推送标签(使用 Axion Release 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:
- master
Run Code Online (Sandbox Code Playgroud)
Fai*_*iry -1
您正在寻找的功能称为工件。工件是成功构建时附加到构建的文件。
要启用 Artifact,请将其放入您的 .gitlab-ci.yml 中:
artifacts:
paths:
- dir/
- singlefile
Run Code Online (Sandbox Code Playgroud)
这会将dir目录和文件上传singlefile回 GitLab。
| 归档时间: |
|
| 查看次数: |
13666 次 |
| 最近记录: |