Offers alternative types of file parameter that are compatible with Pipeline and do not suffer from the architectural flaws of the type built into Jenkins core.
See JENKINS-27413 and JENKINS-29289 for background.
If you defined a Base64 file parameter named FILE
in the GUI configuration for a Pipeline project, you can access it in a couple of ways:
node {
sh 'echo $FILE | base64 -d'
withFileParameter('FILE') {
sh 'cat $FILE'
}
}
That is: as a Base64-encoded environment variable; or via a temporary file with the decoded content.
A stashed file parameter can also be accessed in a couple of ways:
node {
unstash 'FILE'
sh 'cat FILE'
withFileParameter('FILE') {
sh 'cat $FILE'
}
}
That is: as a stash of the same name with a single file of the same name; or, again, via a temporary file.
You can now declare and use file parameters via Declarative Pipeline syntax:
pipeline {
agent any
parameters {
base64File 'small'
stashedFile 'large'
}
stages {
stage('Example') {
steps {
withFileParameter('small') {
sh 'cat $small'
}
unstash 'large'
sh 'cat large'
}
}
}
}
You can use Base64 parameters for uploading small files in the middle of the build:
def fb64 = input message: 'upload', parameters: [base64File('file')]
node {
withEnv(["fb64=$fb64"]) {
sh 'echo $fb64 | base64 -d'
}
}
Currently there is no mechanism for doing this with stashed files.
Nor can you use the withFileParameter
wrapper here.
You can use Base64 parameters for passing small files to downstream builds:
build job: 'downstream', parameters: [base64File(name: 'file', base64: 'aGVsbG8=')]
Licensed under MIT, see LICENSE