[英]Capturing shell script output from Jenkins Pipeline
我試圖提取git分支並在我的Jenkinsfile中提交信息,如下所示:
def commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
我試着像這樣打印它:
println("Branch: ${branch}, Commit: ${commit}")
我沒有獲得真正的價值,而是留下了這個:
Branch: org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator@545511bf, Commit: org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator@545511bf
我做錯了什么,如何正確檢索我需要的值?
編輯:不,建議的副本不是答案,因為我知道用於檢索我需要的信息的shell命令。 我的問題是信息傳遞給我的方式,作為ClosureModelTranslator
而不是String
。
這個完整的管道對你有用嗎? 使用Pipeline插件2.4為我工作。
pipeline {
agent { label 'docker' }
stages {
stage("test_capture_output_and_print") {
steps {
script {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
println("commitSha: ${commitSha}")
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.