I need a plugin where a team lead can approve if a pipeline can move to the next stage in Jenkins. I am planning to use multistage pipeline(declarative) so after dev stage I need a person to approve(only he can approve) and the developer folks can just run the job. Is there any such plugin available so that only one person can approve such request?
tried role based access plugin but here there is no ways to control segregate people who can do stage approvals
CodePudding user response:
@sidharth vijayakumar, I guess you can make use of the 'Pipeline: Input Step' plugin.
As per my understanding, this plugin pauses Pipeline execution and allows the user to interact and control the flow of the build.
The parameter entry screen can be accessed via a link at the bottom of the build console log or via link in the sidebar for a build.
message This parameter gives a prompt which will be shown to a human:
Ready to go?
Proceed or Abort
If you click "Proceed" the build will proceed to the next step, if you click "Abort" the build will be aborted.
Your pipeline script should look like some what similar to below snippet
// Start Agent
node(your node) {
stage('Checkout') {
// scm checkout
}
stage('Build') {
//build steps
}
stage('Tests') {
//test steps
}
// Input Step
{
input message: 'Do you want to approve if flow can proceeded to next stage?', ok: 'Yes'
}
stage('Deploy') {
...
}
}
Reference link : https://www.jenkins.io/doc/pipeline/steps/pipeline-input-step/
CodePudding user response:
To solve the problem of role based approval i used input block with submitter. This means that person who listed as the submitter will only be able to give stage approvals.
stage('Approval') {
agent none
steps {
script {
def deploymentDelay = input id: 'Deploy', message: 'Deploy to production?', submitter: 'rkivisto,admin', parameters: [choice(choices: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'], description: 'Hours to delay deployment?', name: 'deploymentDelay')]
sleep time: deploymentDelay.toInteger(), unit: 'HOURS'
}
}
}
Please note there submitter must be a valid user. Use role based access plugin and create a user with relevant access.
Reference link for the script : https://support.cloudbees.com/hc/en-us/articles/360029265412-How-can-I-approve-a-deployment-and-add-an-optional-delay-for-the-deployment