Jenkins Leck Integration

Non ho usato la notifica allentata perché voglio personalizzare stile / stato / messaggio, ecc. Quindi ho scritto un job chiamato send_slack_notification invece. Ogni volta che voglio informare il allentato API basta chiamare questo lavoro dopo la compilazione.

Ecco il codice in “Esegui Shell”, ho usato curl, sed e per eseguire il lavoro:

# 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

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *