-
-
Save bdwyertech/24976d4554354c66dd3b23ef1be005b3 to your computer and use it in GitHub Desktop.
example rundeck notification plugin that triggers a jenkins job via a curl command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.dtolabs.rundeck.plugins.notification.NotificationPlugin; | |
import groovy.text.SimpleTemplateEngine | |
/** | |
* This plugin executes a curl command with some arguments as defined | |
* by the user in the GUI. It wraps an invocation like shown below | |
* | |
* curl --user <your_jenkins_username>:<your_jenkins_API_key> http://<jenkins_job_url> | |
* | |
*/ | |
rundeckPlugin(NotificationPlugin){ | |
//plugin title shown in GUI | |
title="Trigger a Jenkins Job" | |
//plugin description shown in GUI | |
description="Invokes the Jenkins job URL." | |
//define configuration options for the plugin | |
configuration{ | |
jenkinsUser title:"Jenkins User", required:true | |
jenkinsApiKey title:"Jenkins API Key", required:true | |
jenkinsUrl title:"Jenkins Job URL (eg, http://jenkins/job/myjob/build)", required:true | |
} | |
/** | |
* common closure used for all the notification triggers | |
*/ | |
def handleTrigger = { | |
//with no closure args, there is a "config" and an "execution" variable in the context | |
//create a new list starting with the base shell command | |
def shellCommand=['curl', '-sf', '--user', "${configuration.jenkinsUser}:${configuration.jenkinsApiKey}", configuration.jenkinsUrl] | |
def command=new ArrayList(shellCommand) | |
println "INFO: jenkins-notification-curl: triggering job: ${configuration.jenkinsUrl}" | |
//execute the command as a process and copy the output to the System streams | |
def proc = command.execute() | |
proc.waitForProcessOutput(System.out,System.err) | |
//finally return true if the process exited with 0 exitcode | |
proc.exitValue()==0 | |
} | |
//define handlers for the notification events | |
onsuccess handleTrigger | |
onfailure handleTrigger | |
onstart handleTrigger | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment