jenkins - Jenkins 文件差异与声明性管道和多分支
问题描述
我有一个场景,我在同一个 repo 中管理两个管道,有两个不同的 Jenkinsfiles。
我已经设置了两个 Jenkins 多分支管道来处理两个不同的 Jenkinsfiles,通过路径发现并设置 github webhook 以在特定分支上创建 PR 时触发构建。
我还没有找到一种方法来更改特定 PR 的文件,所以我想通过这样做来利用 git,git diff --name-status origin/master...HEAD
但它失败了,因为 Jenkins 只检查目标分支。
日志存储:
using credential github-user-token-uname-pwd
Fetching changes from the remote Git repository
Fetching without tags
> git rev-parse --is-inside-work-tree # timeout=10
> git config remote.origin.url https://github.com/myreponame # timeout=10
Fetching upstream changes from https://github.com/myreponame
> git --version # timeout=10
using GIT_ASKPASS to set credentials Github token in uname-pwd form used by jenkins to register and manage webhooks
> git fetch --no-tags --force --progress https://github.com/myreponame +refs/heads/BRANCH-X:refs/remotes/origin/BRANCH-X
Checking out Revision 440df9b08667458fa4ade4be57ecbf59a4 (BRANCH-X)
Commit message: "move post build where it belongs"
> git config core.sparsecheckout # timeout=10
> git checkout -f 440df9b08667458fa4ade4be57ecbf59a4
> git rev-list --no-walk ab28e843c0fc7807c4cbd2d6f612e5d76b # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $SECRET_ACCESS_KEY or $ACCESS_KEY_ID
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] sh
+ git diff --name-status origin/master...HEAD
和我得到的错误:
fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree.
有没有办法在多分支管道中检索 PR 的文件更改或让 Jenkins 能够发现所述 PR 的源分支?
解决方案
所以这就是我必须做的。我面临的错误是由于 Jenkins 使用多分支管道的默认签出行为:它签出并跟踪一个分支,并且只跟踪该分支,它不获取其他分支。我最终添加了
options {
skipDefaultCheckout true
}
以及检查所有原始远程分支的阶段
stage('Checking out repo'){
steps {
script {
checkout(
[
$class: 'GitSCM',
branches: [[name: 'origin/FEATUREBRANCH*']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'LocalBranch'],
[$class: 'CleanBeforeCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'github-deploy-key',
url: 'git@github.com:myawesomerepo.git']]
]
)
}
}
}
推荐阅读
- javascript - 检测给定的三个单词字符串中的连字符模式
- python - 如何绕过 Instagram 解析保护?
- javascript - 拆分字符串包含 html 标签
- rust - 铸造钢筋混凝土
到 Rc - python-3.x - 带有 CLI 实用程序的私有仓库中的 Python 包 - 如何部署、使用和构建
- javascript - 输入中的特殊字符以 %nn 形式出现
- javascript - 无法理解 Redux-Saga 中的非阻塞调用
- algorithm - 合并排序算法合并功能不起作用
- vue.js - Axios PUT 对 DRF Api 的请求通过,但未更新
- aws-cdk - 如何在 aws cdk 中使用自定义资源将文件上传到 s3 存储桶