Trying to add Jenkins approval stage before the deployment of MuleSoft API in CloudHub.

Hello Everyone, I am trying to add Jenkins approval stage before the deployment of MuleSoft API in CloudHub. I installed Email extension plugin and used below script in my pipeline. I am able to get approval pop-up in Jenkins dashboard but is unable to send approval email link on my approval’s mail id. Currently I am using Jenkins version 2.440.1.

pipeline {
    agent any
 
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                // Add your build steps here
            }
        }
        stage('Approval') {
            steps {
                script {
                    // Send email notification
                    emailext(
                        subject: "Approval Needed for Job ${env.JOB_NAME}",
                        body: "Please approve the build by clicking on the following link: ${env.BUILD_URL}input/",
                        to: "approver@example.com"
                    )
 
                    // Wait for approval
                    input message: 'Do you approve this build?', submitter: 'approver@example.com'
                }
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying...'
                // Add your deployment steps here
            }
        }
    }
}

And Strange thing is that I used Post Deployment Email stage as well to notify the build status and that is working fine and we are getting the Email as well based on the build status. Used below script in Jenkinsfile.

post {
    failure {
        mail to: 'team@example.com',
             cc: 'team2@examlpe.com',
             subject: "Failed:  Build ${env.JOB_NAME}",
             body: "Build failed ${env.JOB_NAME} and Build number: ${env.BUILD_NUMBER} .\n\n View the logs at : \n ${env.BUILD_URL}"
    }

 success {
        mail to: 'team@example.com',
             cc: 'team2@examlpe.com',
             subject: "Successful : Build ${env.JOB_NAME}",
             body: "Build Successful ${env.JOB_NAME} and Build number: ${env.BUILD_NUMBER} .\n\n View the logs at : \n ${env.BUILD_URL}"
    }

}

Anyone’s input is much appreciated.

Hello and welcome to this community, @Dalbir_singh. :wave:

The issue you’re facing might be due to the fact that the emailext function and the input function are not linked. As far as I know, the input function is not aware of the email sent by emailext. :thinking:
The input function only pauses the Pipeline and waits for the user with permissions to continue. The submitter parameter in the input function is used to specify the users who have permission to approve or reject.

If you want to send an email to the approver with a link to approve or reject the build, you might need to implement a custom solution. One way to do this would perhaps be to create a simple web application that interacts with the Jenkins API. When the approver clicks on the link in the email, they are directed to this web application which then sends an API request to Jenkins to approve or reject the build.

However, this would require additional development and might not be the best solution if you’re looking for a quick fix. :person_shrugging:

As an alternative, you could maybe use the emailext function to send an email to the approver with a link to the Jenkins job. The approver would then need to manually navigate to the job and click the “Proceed” or “Abort” button in the Jenkins UI.

Thanks @poddingue for your response. As an alternative you are saying use the emailext function to send an email to the approver with a link to the Jenkins job. The approver would then need to manually navigate to the job and click the “Proceed” or “Abort” button in the Jenkins UI. So to achieve this what should be the script syntax . I mean I should first write Emailext script in 1st stage and input function in another stage of the pipeline. Is my understanding is correct?