| Hi, This would be a great improvement for use with declarative pipeline. We now have the case where we only perform a checkout in the stages where applicable. It could help to have some syntax like:
pipeline {
stages {
stage('Build') {
steps {
withEnv(checkout(scm)) {
echo 'printenv'
echo 'Perform the build'
}
}
}
}
}
On the other hand, we still have the case that checkout and withEnv are in separate steps. We would something like the following (not that this example won't work because of the variable assignment!):
pipeline {
stages {
stage('Build') {
steps {
def scmVars = checkout(scm)
echo 'Preparing the build'
withEnv(scmVars) {
echo 'printenv'
echo 'Perform the build'
}
}
}
}
}
Our current workaround is to set the scmVars as a global variable and then "translate" it into a list for use with withEnv:
import groovy.transform.Field
@Field XRA31_SCM_VARS = null
/**
* Sets the XRA31_SCM_VARS variables to the output of the `checkout` command
*/
def xra31_prepare_source(steps, scm) {
XRA31_SCM_VARS = steps.checkout changelog: false, poll: false, scm: scm
}
def flatten_map(Map m) {
List l = []
m.each { k,v ->
l.add([k, v].join('='))
}
return l
}
pipeline {
stages {
stage('Build') {
steps {
xra31_prepare_source(this, scm)
echo 'Preparing the build'
withEnv(flatten_map(XRA31_SCM_VARS)) {
echo 'printenv'
echo 'Perform the build'
}
}
}
}
}
It would be great to see a solution for the latter case since we use/need it extensively. With best regards, Tom. |