Как я могу заставить Jenkins извлечь значение из вывода консоли, сгенерированного командой в Jenkinsfile?
В частности, как я могу заставить Дженкинса извлечь хеш коммита из результатов команды checkout scm
в следующем очень простом Jenkinsfile?
Jenkinsfile
node {
// Clean workspace before doing anything
deleteDir()
try {
stage ('Clone') {
checkout scm
}
} catch (err) {
currentBuild.result = 'FAILED'
throw err
}
}
Вывод команды checkout scm
:
Журнал Jenkins печатает следующее в результате выполнения команды checkout scm
в приведенном выше упрощенном файле Jenkinsfile:
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
> git init /var/jenkins_home/workspace/le-repo_sample-issue-branch-2WOFDGRDQWR367VAM7O26H2DKPTRVPDKRTGNRIS4AQNNFP7QIX2Q # timeout=10
Fetching upstream changes from http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --no-tags --progress http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git +refs/heads/sample-issue-branch:refs/remotes/origin/sample-issue-branch
> git config remote.origin.url http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/sample-issue-branch:refs/remotes/origin/sample-issue-branch # timeout=10
> git config remote.origin.url http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git # timeout=10
Fetching without tags
Fetching upstream changes from http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git
using GIT_ASKPASS to set credentials
> git fetch --no-tags --progress http://<bitbucket-ip-on-lan>:7990/scm/JSP/jenkinsfile-simple-repo.git +refs/heads/sample-issue-branch:refs/remotes/origin/sample-issue-branch
Checking out Revision 77cf12f42136efc77fecbcd1f761a54254278cb3 (sample-issue-branch)
> git config core.sparsecheckout # timeout=10
> git checkout -f 77cf12f42136efc77fecbcd1f761a54254278cb3
Commit message: "add whitespace"
> git rev-list --no-walk e975fb4391677bc09f2056b3e8a6be62eda0b222 # timeout=10
[Bitbucket] Notifying commit build result
Пересмотренный вопрос:
В частности, что мы добавляем в файл Jenkinsfile, чтобы в конце журнала дополнительно выводилось следующее:
Commit hash is: 77cf12f42136efc77fecbcd1f761a54254278cb3
Это явно слишком упрощенно. Печатный вывод в реальной жизни войдет в переменную и будет передан в качестве аргумента в скрипт. Но для этого OP какой синтаксис позволит Jenkins извлечь хеш коммита?