【发布时间】:2019-09-08 02:44:54
【问题描述】:
我正在创建一个用于 GitHub Enterprise 的 Jenkinsfile。我使用管道作业中的 GUI 设置来指定来自 GitHub 存储库的 Jenkinsfile。
我正在使用脚本语法而不是声明性语法。
我可以使用checkout scm 在我的 Jenkinsfile 中签出 repo。我想在我的脚本中使用一些关于结帐的信息,例如分支名称和提交哈希。但是,我不知道如何访问scm 类的变量。
当我运行作业时,它在 Checkout 阶段失败。从 git 结帐似乎工作正常,但它失败而没有打印任何错误。如果我删除 echo scm.GIT_BRANCH 行,它可以正常工作。
node {
stage('Checkout') {
checkout scm
echo scm.GIT_BRANCH
}
}
这是输出:
Started by user spark
Obtained nightly/Jenkinsfile from git https://github.enterprise.instance.com/spark/ci_flow_test
[Pipeline] node
Running on jenkins-server in /home/spark/ci_flow_test/pipeline_test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout
> /apps/git/git18/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> /apps/git/git18/bin/git config remote.origin.url https://github.enterprise.instance.com/spark/ci_flow_test # timeout=10
Fetching upstream changes from https://github.enterprise.instance.com/spark/ci_flow_test
> /apps/git/git18/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials
> /apps/git/git18/bin/git fetch --tags --progress https://github.enterprise.instance.com/spark/ci_flow_test +refs/heads/*:refs/remotes/origin/*
> /apps/git/git18/bin/git rev-parse refs/remotes/origin/working^{commit} # timeout=10
> /apps/git/git18/bin/git rev-parse refs/remotes/origin/origin/working^{commit} # timeout=10
Checking out Revision 396f172c6061ba2760a71cba817df24836ec7e3b (refs/remotes/origin/working)
Commit message: "try echo"
> /apps/git/git18/bin/git config core.sparsecheckout # timeout=10
> /apps/git/git18/bin/git checkout -f 396f172c6061ba2760a71cba817df24836ec7e3b
> /apps/git/git18/bin/git rev-list 778c36171927020bd1afbd7206d86bf94abd1ed8 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] mail
[Pipeline] echo
Post script
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE
【问题讨论】:
标签: jenkins github groovy jenkins-pipeline