jenkins - Jenkins Pipeline - Jenkins SCM 步骤。结帐返回不参考提供的参数的无效数据
问题描述
我正在为我的项目设置 CI/CD,并决定使用 Jenkins Pipeline。我基本上需要什么:
- 从选定的分支构建(从下拉列表中选择)
- 有条件地执行一些阶段(取决于分支)
我将管道配置为从 scm 获取 Jenkinsfile: 然后我决定编写 cutom scm checkout 如下:
stage('Checkout specific branch') {
steps {
echo "Checking out ${params.branchToBuild}..."
script {
def actualBranchCheckout = checkout([$class: 'GitSCM',
branches: [
[name: "${params.branchToBuild}"]
],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'LocalBranch', localBranch: "**"]],
submoduleCfg: [],
userRemoteConfigs: [
[credentialsId: "${env.REPO_SSH_CREDS_ID}", url: "${env.REPO_SSH_URL}"]
]
])
}
}
}
我有几个担忧。GIT_ 环境变量在签出 Jenkinsfile 的分支时设置。
GIT_BRANCH=origin/master
GIT_COMMIT=11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_LOCAL_BRANCH=master, GIT_PREVIOUS_COMMIT=11a5800b6ca31bc81545fa4874d73fa275c820c2
这很好,但是当我执行结帐时,并没有使用实际值进行更新并且保持不变。好的,该方法本身返回的地图可能包含我需要的内容,因此我可以手动重置它们,对吗?但是在查看开发分支时它们结果是相同的:
以下是日志:
Obtained Jenkinsfile from git git@bitbucket.org:team/repo.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Repo/repo_pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential jenkins-bitbucket
Cloning the remote Git repository
Cloning repository git@bitbucket.org:team/repo.git
> git init /var/lib/jenkins/workspace/Repo/repo_pipeline # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
> git --version # timeout=10
using GIT_SSH to set credentials
> git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
using GIT_SSH to set credentials
> git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 31e727bf81b3379c9aa80224b8f941bc867acd77 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 31e727bf81b3379c9aa80224b8f941bc867acd77
Commit message: "print out variables"
> git rev-list --no-walk 11a5800b6ca31bc81545fa4874d73fa275c820c2 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout specific branch)
[Pipeline] echo
Checking out develop...
[Pipeline] script
[Pipeline] {
[Pipeline] checkout
using credential jenkins-bitbucket
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git@bitbucket.org:team/repo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:team/repo.git
> git --version # timeout=10
using GIT_SSH to set credentials
> git fetch --tags --progress git@bitbucket.org:team/repo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse origin/develop^{commit} # timeout=10
Checking out Revision 11a5800b6ca31bc81545fa4874d73fa275c820c2 (origin/develop)
> git config core.sparsecheckout # timeout=10
> git checkout -f 11a5800b6ca31bc81545fa4874d73fa275c820c2
> git branch -a -v --no-abbrev # timeout=10
> git checkout -b develop 11a5800b6ca31bc81545fa4874d73fa275c820c2
Commit message: "another try"
First time build. Skipping changelog.
[Pipeline] echo
[GIT_BRANCH:origin/master, GIT_COMMIT:31e727bf81b3379c9aa80224b8f941bc867acd77, GIT_LOCAL_BRANCH:master, GIT_PREVIOUS_COMMIT:11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_PREVIOUS_SUCCESSFUL_COMMIT:11a5800b6ca31bc81545fa4874d73fa275c820c2, GIT_URL:git@bitbucket.org:team/repo.git]
我还有另一种选择手动完成所有操作,例如git rev-parse --abbrev-ref HEAD
分支等。有谁知道如何解决这个问题/这是一个已知问题还是我做错了什么?
解决方案
推荐阅读
- stack - 如何将一个圆圈中心化为一张卡片?
- php - Laravel Eloquent:SQL 注入预防是自动完成的吗?
- kubernetes - 如何在 master 上找到 kubeadm 的 join 命令?
- php - 将 HTML 表格放入特定区域
- javascript - ES6:在同一个函数中访问两个不同的作用域(类全局和对象局部)
- laravel-5.4 - Route Slug 总是被查询 - Laravel 5.4
- javascript - 在 for 循环中分组项目
- widget - 如何在 Flutter 中为 Container Widget 下划线
- mongodb - 旋转MongoDB收集效率
- python - 如何计算 MXNet 中损失函数的粗麻布?