Closed clumbo closed 5 years ago
Also interested but for freestyle project. I'm not able to find any information on how to specify a changeset to update to using the plugin.
Hi!
We recently released plugin version 2.22, which adds build parameter resolution in the Plastic SCM selector configuration for pipelines. That would allow you to use build parameters (surrounded by %
, like %branchName%
) in the Plastic SCM selector. This enables you to retrieve the Jenkinsfile
from different branches/changesets dynamically.
That said, you can also set those build parameters as well in the Jenkinsfile
using the params
directive. More info here: https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-parameters
Basically, you just need to define parameters using the same name and type as you did in the project definition. Then, you can use those parameters in the cm
command inside your Jenkinsfile
.
Is this what you were trying to achieve?
Regards, Miguel
Thanks,
I was hoping it would work with the "checkout scm" Jenkinsfile command rather than calling the cm command directly.
Am I missing something?
That should work if you install v2.22, set up build parameters and apply them in the Plastic SCM selector used to retrieve the Jenkinsfile as I suggested above. checkout scm
should use the same configuration, please let us know if it doesn't.
Thanks
So if I want to have a build param where I can specify a changeset number, How would I pass this to a "checkout scm" command in my jenkinsfile?
When you set the Pipeline description source, select Pipeline Script from SCM and select Plastic SCM as the SCM of choice. There you can set the Plastic SCM checkout configuration (selector) that should be used by checkout scm
later on. If you run into any issue please let us know.
Sorry, I don't think i'm understanding correctly
I have a paramater called changeset, how do I pass this parameter to the checkout scm command in the script.
pipeline { parameters { string(changeset: '', defaultValue: '', description: 'if set checkout and build specific version') } options { skipDefaultCheckout() timeout(time: 4, unit: 'HOURS') } stages { stage('Checkout') { steps { checkout scm } }
I noticed you can specifically set params on the git plugin like so, but not sure what to use for plasticscm
checkout scm: [ $class: 'GitSCM', branches: scm.branches, doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: scm.userRemoteConfigs ]
Is it possible todo the above with script?
Using the snippet generator at https://my.jenkins.server.io/job/${job_name}/pipeline-syntax/ you can achieve what you want:
checkout([$class: 'PlasticSCM', selector: '''repository "default"
path "/"
smartbranch "/main" changeset "11157" ''', useMultipleWorkspaces: false, useUpdate: true, workspaceName: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}'])
Could you please share your job configuration?
Thats perfect
Many Thanks
How do I select a specific changeset via Jenkinsfile with the checkout command?