HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Jenkins input pipeline step - Give submitter as a group

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
groupjenkinsgiveinputstepsubmitterpipeline

Problem

I could find that “submitter” parameter accepts individual user IDs and external LDAP groups. But “Jenkins-local” groups defined by any authorization strategy are not working. I have a limitation not to use external LDAP groups.

The workaround that I have used is define the comma separated list of individual users as a Jenkins global variable and manage the list from there. This gives a better maintainability. However, it mandates that the stage is wrapped within node. As the pipeline waits for the approver to approve this step, it holds a node instance and this causes the rest of the jobs to wait for available instances. Is there a way to use a Jenkins global variable outside of node for the input step?

node{
stage ('Approve?')
{
    timeout(time:2, unit:'DAYS')
    {
        input message: 'Can you approve this ??', submitter: MY_APPROVERS
    }
}


}

Solution

We have moved onto using Jenkins templates and I have a workaround to keep the individual approver names list in one place. Sharing the sample code for your reference.

#!/usr/bin/env groovy
import com.mm.Constants 
def call(String teamName = 'LOGIN') {
   // team name of null means UI
   teamName = teamName ?: 'UI'

   timeout(time:2, unit:'DAYS')
       {                                                              
           input message: 'Can you approve this ??', submitter: Constants."${teamName}_APPROVERS"
      }


}

#!/usr/bin/env groovy
class Constants {
   static final LOGIN_APPROVERS = 'approver1,approver2';
   static final UI_APPROVERS = 'approver2,approver3';
}


Below is how you call from the pipeline

stage ('Ship to QA?'){
    echo "Waiting for QA approval"
    shipToQA('LOGIN')
}

Code Snippets

#!/usr/bin/env groovy
import com.mm.Constants 
def call(String teamName = 'LOGIN') {
   // team name of null means UI
   teamName = teamName ?: 'UI'

   timeout(time:2, unit:'DAYS')
       {                                                              
           input message: 'Can you approve this ??', submitter: Constants."${teamName}_APPROVERS"
      }
#!/usr/bin/env groovy
class Constants {
   static final LOGIN_APPROVERS = 'approver1,approver2';
   static final UI_APPROVERS = 'approver2,approver3';
}
stage ('Ship to QA?'){
    echo "Waiting for QA approval"
    shipToQA('LOGIN')
}

Context

StackExchange DevOps Q#4863, answer score: 1

Revisions (0)

No revisions yet.