Created
February 2, 2017 04:14
-
-
Save smalltown/e25d8eb01899368985184ac1f9ea1c84 to your computer and use it in GitHub Desktop.
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
import groovy.json.* | |
def deploy(phase, version, user, branch, status = 'Success', region = 'Oregon', channel = 'none', repoer = 'true', repo_host, repo_owner) { | |
def slack_info = slack_info.load() | |
def http_client = new com.droi.pipeline.jenkins.httpRequest(slack_info.hook_protocol, slack_info.hook_fqdn, slack_info.hook_port.toInteger()) | |
def header = ["Content-Type": "application/json"] | |
def url = "${slack_info.hook_protocol}://${slack_info.hook_fqdn}/${slack_info.hook_uri}" | |
def response = [:] | |
def color = (status == 'Success') ? 'good' : 'danger' | |
def deliver_channel = (channel == 'none') ? slack_info.channel.deploy : channel | |
def payload = [:] | |
payload['channel'] = deliver_channel | |
payload['username'] = slack_info.user_name | |
payload['icon_emoji'] = slack_info.icon | |
payload['attachments'] = [] | |
payload['attachments'][0] = [:] | |
payload['attachments'][0]['pretext'] = 'Deploymemt Information as Below:' | |
payload['attachments'][0]['color'] = color | |
payload['attachments'][0]['fields'] = [] | |
payload['attachments'][0]['fields'].add(['title': 'Job:', 'value': JOB_NAME, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Region:', 'value': region, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Phase:', 'value': phase, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Version:', 'value': version, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Started By:', 'value': user, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Status:', 'value': status, "short": true]) | |
payload['attachments'][0]['fields'].add(['title': 'Detail:', 'value': "<${BUILD_URL}|Jenkins Job URL>", "short": true]) | |
payload['attachments'][0]['fields'].add( (repoer == 'true') ? ['title': 'Change Log:', 'value': "<http://${repo_host}/${repo_owner}/${JOB_BASE_NAME}/blob/${branch}/CHANGELOG.md|CHANGELOG.md URL>", "short": true] : ['title': 'Change Log:', 'value': 'None', "short": true] ) | |
payload_json = new JsonBuilder( payload ).toPrettyString() | |
response = http_client.postRequest(url, payload_json, header) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment