Ankit Gupta
Ankit Gupta

Reputation: 21

jenkins pipeline input via email

I am using Jenkins pipeline I want user to give input via email I tried this but didnt helped.

def tok = UUID.randomUUID().toString()
mail to: 'admins@mycorp', subject: 'Ready to roll?', mimeType: 'text/html',
body: """Please <a href="${env.JENKINS_URL}pipeline-inputs/${tok}/proceed">approve me</a>!"""
input message: 'Ready?', token: tok

Any pointer about this, I want token or any type of authentication also. Thanks in advance

Upvotes: 1

Views: 5984

Answers (1)

Roc King
Roc King

Reputation: 481

        emailext mimeType: 'text/html',
                 subject: "[Jenkins]${currentBuild.fullDisplayName}",
                 to: "[email protected]",
                 body: '''<a href="${BUILD_URL}input">click to approve</a>'''

        def userInput = input id: 'userInput',
                              message: 'Let\'s promote?', 
                              submitterParameter: 'submitter',
                              submitter: 'tom',
                              parameters: [
                                [$class: 'TextParameterDefinition', defaultValue: 'sit', description: 'Environment', name: 'env'],
                                [$class: 'TextParameterDefinition', defaultValue: 'k8s', description: 'Target', name: 'target']]

        echo ("Env: "+userInput['env'])
        echo ("Target: "+userInput['target'])
        echo ("submitted by: "+userInput['submitter'])

Tom will receive a mail containing the input url, and only tom can submit the input successfully.

Upvotes: 6

Related Questions