Jenkins Slack Integration (Galego)

Non uso a notificación de folga porque quero personalizar o estilo / estado / mensaxe, etc. Entón escribín un job chamado send_slack_notification no seu lugar. Cada vez que quero notificar a API Slack só chame a este traballo despois de compilar.

Aquí está o código en “Executar Shell”, usei curl,

e jsawk para facer o traballo:

# URL to get the built info json# will get "http://JENKINS_PATH/job/JOB_NAME/97/api/json"NEW_URL="http://jks_username:[email protected]"$(echo ${BUILD_URL} | sed -r 's/http:\/\///g')"/api/json"# Cut the JOB_NAME part from BUILD_URLJOB_NAME=$(echo ${BUILD_URL} | sed -n 's/.*\/job\/\(.*\)\/.*/\1/p' | sed "[email protected][email protected] @g;[email protected]%@\\\\[email protected]" | xargs -0 printf "%b")# Get the built info jsonJSON=$(curl $NEW_URL)STATUS=$(echo $JSON | /usr/local/bin/jsawk "return this.result")BUILD_INFO=$(echo $JSON | /usr/local/bin/jsawk "return this.displayName")TIME=$(echo $JSON | /usr/local/bin/jsawk "return this.duration")TIME=$(echo "scale=4; $TIME/1000" | bc -l)# Cut the usernameUSER=$(echo $JSON | /usr/local/bin/jsawk "return this" | sed -n "s/.*Started\ by\ \(*\).*/\1/p")# Customize the message sending to slackTEXT=$JOB_NAME" Built by "$USER", it took "$TIME" seconds."# Send notification using Slack API# will send to https://hooks.slack.com/services/BLABLABLA/BLABLABLAcurl -X POST -H 'Content-type: application/json' --data '{"channel": "#production_info","username": "jenkins-bot","icon_emoji": ":lol:","text": "'"$TEXT"' (<'"$BUILD_URL"'|Open>)", "attachments": }]}' https://hooks.slack.com/services/BLABLABLA/BLABLABLA/BLABLABLABLABLABLA

Leave a Comment

O teu enderezo electrónico non se publicará Os campos obrigatorios están marcados con *