Skip to main content

Jenkins

/lib/systemd/system/jenkins.service

Config

flightplan yarn

https://cms.staffanstorp.se/wp-admin/options-general.php?page=whitespace-headless-cms

Installation

Uncomment the following row to enable the prefix (/jenkins) Environment="JENKINS_PREFIX=/jenkins" in: /lib/systemd/system/jenkins.service

https://<USERNAME>:<API-TOKEN>@<JENKINS-URL>/<JENKINS-PREFIX>/job/<JOB-NAME>/buildWithParameters?CLEAN=false&token=<JOB-TOKEN>&cause={DESCRIPTION}

Test url:

curl -X POST http://USER_ID_JENKINS_RECEIVER:TOKEN_OF_USER_ID_JENKINS_RECEIVER@URL_JENKINS_RECEIVER:PORT/job/NAME_OF_JOB/buildWithParameters?token=TOKEN_JOB_JENKINS_RECEIVER

Slack notifications

In order to get slack notifications for a new Jenkins pipeline, add these lines to the Jenkinsfile right before the finishing }:

  post {
failure {
script {
def userIds = slackUserIdsFromCommitters()
def userIdsString = userIds.collect { "<@$it>" }.join(' ')
slackSend(botUser: true, color: 'danger', message: "Build Failed - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>) $userIdsString")
}
}
fixed {
script {
def userIds = slackUserIdsFromCommitters()
def userIdsString = userIds.collect { "<@$it>" }.join(' ')
slackSend(botUser: true, color: 'good', message: "Build Fixed - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>) $userIdsString")
}
}
}

If the pipeline is being set up on a new Jenkins installation also follow these steps:

  1. Add a new credential called slack-token of type secret text and paste in the token found here: https://api.slack.com/apps/A07KJ4EL2GK/install-on-team
  2. Install the plugin Slack Notification
  3. Go to Manage Jenkins -> System and down to the Slack section
  4. Set workspace to white
  5. Set the newly generated credential
  6. Set default channel to #jenkins-notifications
  7. Check the Custom slack app bot user box