我对jenkins管道有以下脚本,该脚本试图获取git成功的提交, 有人可以帮我为什么可变值不打印吗?
node(params.node)
{
try{ stage('fetchCommandOutput'){
dir('test'){
powershell"""
def succesfulCommit=getCommandOutput("git rev-parse HEAD") //this is not working
echo "git successful commit is " $succesfulCommit
exit 0
"""
}
}
}
catch(Exception e){
echo e.toString()
}
}
def getCommandOutput(cmd) {
if (isUnix()){
return sh(returnStdout:true , script: '#!/bin/sh -e\n' + cmd).trim()
} else{
stdout = bat(returnStdout:true , script: cmd).trim()
result = stdout.readLines().drop(1).join(" ")
echo "result is ${result}" \\\\this works fine
return result
}
}
答案 0 :(得分:0)
您已在管道中将getCommandOutput(cmd)
定义为Groovy函数。因此,仅在powershell
步内调用它是行不通的。将表达式def succesfulCommit=getCommandOutput("git rev-parse HEAD")
和后续代码行移到powershell
步骤之外。