我正在寫一個Jenkinsfile其開始爲這樣的:Jenkinsfile聲明管道 - 捕獲所有結賬單片機輸出
pipeline {
agent {
label 'ec2-slave'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
...
我想捕捉checkout scm
調用的輸出,因爲我需要使用git的相關信息在後續步驟中。
這當然步驟奇妙運行時,產生輸出如此:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url xxxxxxxxx # timeout=10
Fetching upstream changes from xxxxxxxxx
> git --version # timeout=10
using GIT_SSH to set credentials jenkins ssh key
> git fetch --tags --progress xxxxxxxxx +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen 2 remote branches
> git tag -l # timeout=10
Checking out Revision 10214b72d4c1f2c69444cc79a1af7ecc7f033349 (origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 10214b72d4c1f2c69444cc79a1af7ecc7f033349
> git rev-list 10214b72d4c1f2c69444cc79a1af7ecc7f033349 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url xxxxxxxxx # timeout=10
Fetching upstream changes from xxxxxxxxx
> git --version # timeout=10
using GIT_SSH to set credentials jenkins ssh key
> git fetch --tags --progress xxxxxxxxx +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen 2 remote branches
> git tag -l # timeout=10
Checking out Revision 10214b72d4c1f2c69444cc79a1af7ecc7f033349 (origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 10214b72d4c1f2c69444cc79a1af7ecc7f033349
是否有捕獲和/或引用前面的管道步驟的預期方法?
爲了什麼值得我從自由式語法轉換這個Jenkinsfile。例如,我已經能夠通過將'sh'調用保存到變量中來「引用」前面的步驟。不知道如何用'checkout scm'完成同樣的事情......我確定這是一個簡單的解決方案,但我仍然對Groovy和Jenkinsfiles有所瞭解 – asdoylejr
我也在'script {block}這會產生奇數輸出: 'checkout scm' 'echo「$ {scm.dump()}」' 這會產生一個帶有一堆'null'值的映射,這對我沒有太大幫助。 – asdoylejr