5

I'm trying to get a Parametrized Pipeline Job in Jenkins (2.19.4) to work with the following specs:

  • BRANCH_TO_BUILD Git parameter that retrieves all available branches from a gitlab repository for the user to pick one
  • Groovy Pipeline script that runs different stages that works perfectly when used as a Jenkinsfile from SCM.

The error I'm getting is related to Git Parameter:

net.uaznia.lukanus.hudson.plugins.gitparameter.jobs.WorkflowJobWrapper getSCMFromDefinition
SEVERE: Get repo scm from Workflow job fail
java.lang.NoSuchMethodException: org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition.getScm()

As far as I know Jenkins is not capable of retrieving the SCM configuration from pipeline script before asking for parameter's input.

I know there is a new feature request JENKINS-39530 but is there a different approach to accomplish this?

2 Answers 2

1

From what I understand you want a job where the user selects a branch. The branches should be kept in sync with the branches in GitLab.

One way to do that is with the Job DSL plugin.

  1. Create a job, perhaps called job-creator, that runs every X minutes, or is triggered from GitLab.
  2. Let job-creator run a DSL build step.
  3. The DSL may ask GitLab with REST to get the branches. Loop through the branches to create the pipeline-job.

The job DSL would look similar to this:

...
 pipelineJob("the pipeline job") {
  parameters {
   def branches = ['[Choose]']
   getJson(server+ "/rest/request/to/gitlab...")
    .values
    .each { branch ->
    if (branch.displayId.startsWith('feature')) {
     branches.push(branch.displayId)
    }
   }
   choiceParam(
    'branch',
    branches,
    'Pick a branch.')
  }
...
0

For me I use the Input stage to interact with the user pipeline running. The pipeline is self don't have paramets but at running you have an input that ask user branh they want to build You start pipeline by checking out the git projet, afther you use the worksopace to generate with awk the list of branch on a signe file, and then you user this file to build the choice off the input. you can see the example at this link: enter link description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.