Created
August 31, 2017 07:18
-
-
Save peterjenkins1/39153516b66d080286e5db4449f9c21a to your computer and use it in GitHub Desktop.
Notify deveo without a plugin ... handy when the official plugin doesn't work with Pipelines
This file contains 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
/* | |
In your pipeline you can do: | |
// Notify deveo of build result | |
deveo = load 'jenkins-deveo-notify.groovy' | |
deveo.sendCompletedEvent(params.deveo_url, params.deveo_project, params.deveo_repo, params.deveo_name_string, params.deveo_company_key, params.deveo_account_key) | |
*/ | |
import groovy.json.JsonOutput | |
def sendCompletedEvent(url, project, repository, name, COMPANY_KEY, ACCOUNT_KEY) { | |
// https://app.deveo.com/docs/developer/v1/event/#operations | |
// url - Deveo url (example: https://app.deveo.com) | |
// project - Project name (note common name) | |
// repository - Repository name | |
// name - name of build show in notification | |
// COMPANY_KEY - company key from Deveo | |
// ACCOUNT_KEY - account key from Deveo | |
def GIT_COMMIT = sh ( | |
script: 'git log --pretty=format:"%H" -1', | |
returnStdout: true | |
).trim() | |
def payload = JsonOutput.toJson([ | |
target: "build", | |
operation: "completed", | |
project: project, | |
repository: repository, | |
name: name, | |
commits: [GIT_COMMIT], | |
resources: [RUN_DISPLAY_URL] | |
]) | |
def auth = '''-H \"Authorization: deveo company_key=\'''' + COMPANY_KEY + '''\',account_key=\'''' + ACCOUNT_KEY + ''''\'\" ''' | |
def accept = "-H \"Accept: application/vnd.deveo.v1\"" | |
def contype = "-H \"Content-Type: application/json\"" | |
def content = "-d \'${payload}\'" | |
sh "curl -s -X POST ${auth} ${accept} ${contype} ${content} ${url}/api/events" | |
} | |
def sendFailedEvent(url, project, repository, name, COMPANY_KEY, ACCOUNT_KEY) { | |
// https://app.deveo.com/docs/developer/v1/event/#operations | |
// url - Deveo url (example: https://app.deveo.com) | |
// project - Project name (note common name) | |
// repository - Repository name | |
// name - name of build show in notification | |
// COMPANY_KEY - company key from Deveo | |
// ACCOUNT_KEY - account key from Deveo | |
def GIT_COMMIT = sh ( | |
script: 'git log --pretty=format:"%H" -1', | |
returnStdout: true | |
).trim() | |
def payload = JsonOutput.toJson([ | |
target: "build", | |
operation: "failed", | |
project: project, | |
repository: repository, | |
name: name, | |
commits: [GIT_COMMIT], | |
resources: [RUN_DISPLAY_URL] | |
]) | |
def auth = "-H \"Authorization: deveo company_key='${COMPANY_KEY}',account_key='${ACCOUNT_KEY}'\"" | |
def accept = "-H \"Accept: application/vnd.deveo.v1\"" | |
def contype = "-H \"Content-Type: application/json\"" | |
def content = "-d \'${payload}\'" | |
sh "curl -s -X POST ${auth} ${accept} ${contype} ${content} ${url}/api/events" | |
} | |
return this; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment