Jenkins 找不到 sh 提供的 git SHA 密钥



我有一个Jenkins应用程序,监控SCM的变化,并相应地创建,删除或构建作业。我有一个奇怪的错误与git环境有关。

  • 我使用Jenkins git命令获取数据
  • 我在
  • 之前和之后获得SHA密钥
  • 之后,我在"before"SHA密钥和后面的
  • 我得到一个错误消息,说它找不到"after"沙关键
  • 我不知道这是否与它有关,但是我的git目录似乎已经从/var/lib/jenkins/workspace/jobName移动到/var/lib/jenkins/jobs/jobName/workspace。这似乎是不久前发生的事,我想不起来是怎么回事。

下面是代码。我把它简化了,集中在错误上。

shaBeforePull = currentGitSha()
echo "before git"
git credentialsId: '7a7eaf05-0bdf-457f-81cf-28be7be3a18c', url: 'git@git.ecd.axway.org:documentation/classification_upload_to_zoomin.git'
// PRIVATE_KEY = '../../keys/zoomin-private-key_open.ppk'
echo "after git"
shaAfterPull = currentGitSha()
changedFilesBetweenSha(shaBeforePull, shaAfterPull)
...
def currentGitSha() {
myShCommand = "git rev-parse HEAD"
currentGitSha = sh(returnStdout: true, script: myShCommand)
echo "currentGitSha=$currentGitSha"
return currentGitSha
def changedFilesBetweenSha(sha1, sha2) {
myShCommand = "git diff --name-only ${sha1} ${sha2}"
myShOutput = sh(returnStdout: true, script: myShCommand).trim()
echo "changedFilesBetweenSha = ${myShOutput}"
myFileList = myShOutput.split('n')
return myFileList
}
}

下面是错误输出的一个示例。我缩短了SHA密钥,它们实际上有40个字符长:

+ git diff --name-only d70c...ec05
+ c1c8...a41
/var/lib/jenkins/jobs/_upload_jobs_from_gitlab/workspace@tmp/durable-47bfa16f/script.sh: 2: c1c8f...a41: not found
axway.zoominsoftware.io/confluence/AGGGG/EBICSClient_11_MigrationGuide_allOS_en_HTML5-excel.xml
axway.zoominsoftware.io/confluence/AGGGG/custom.properties
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: script returned exit code 127

问题是由于SHA字符串中的寄生虫n造成的。通过修剪返回的SHA字符串解决了这个问题。参见下面的.trim().replace('n', '')

def currentGitSha() {
myShCommand = "git rev-parse HEAD"
currentGitSha = sh(returnStdout: true, script: myShCommand)
echo "currentGitSha=$currentGitSha"
currentGitSha = currentGitSha.trim().replace('n', '')
return currentGitSha
}

输出现在是

+ git diff --name-only d70c...ec05 c1c8...a41

而不是

+ git diff --name-only d70c...ec05
+ c1c8...a41

相关内容

  • 没有找到相关文章

最新更新