How can a file from the current workspace be passed as a parameter to a build job, e.g.:
build job: 'other-project', parameters: [[$class: 'FileParameterValue', ????]]
What a nightmare - there is no documentation, looked into jenkins code, etc.. Tried everything
Eventually found out that this doesn't currently work. Here is the jenkins bug.
https://issues.jenkins-ci.org/browse/JENKINS-27413
Linked to from here: http://jenkins-ci.361315.n4.nabble.com/pipeline-build-job-with-FileParameterValue-td4861199.html
You need to pass in a FileParameterValue
http://javadoc.jenkins.io/hudson/model/FileParameterValue.html
This approach assumes you have the file in the current job's workspace.
pipeline
{
agent any
stages {
stage('Pass file type param to build job') {
steps {
script {
def propertiesFilePath = "${env.WORKSPACE}/sample.properties"
build job: 'other-project',
parameters: [[$class: "FileParameterValue", name: "propertiesFile", file: new FileParameterValue.FileItemImpl(new File(propertiesFilePath))]]
}
}
}
}
}
Here the name of the downstream/child job is 'other-project' and the name of the file type parameter in this downstream/child job is 'propertiesFile'. The type FileParameterValue.FileItemImpl is defined in the class FileParameterValue and is internally used in jenkins to handle FileItem, also adding serialization support to the same.