Skip to content

Commit

Permalink
114 email on failure (#58)
Browse files Browse the repository at this point in the history
* Attempt to find commit author from env vars

* Add another check for env

* Attempt t get email from api

* Add debug statement

* Add ands

* Use powershell as well

* Make call from powershell as well

* Echo email

* Escape $

* Find out payload

* Add call to api user

* reformat curl call

* Escape $

* using correct json path to email

* Attempt to use without conversoin

* Retrieve string

* Move into script step

* Add failing test and email

* Move mail outside

* Move into script

* Move into node

* Get email earlier

* Try getting from API

* Move CC back

* Remove incorrect echoes

* Remove silent

* Work out what we have to work with

* Try to set in environment

* Try retrieve email in stages

* Try retrieve email in stages

* Better function

* Fix too many brackets

* Fix exits and tls

* test with echoes

* Try using && everywhere

* Remove && and attempt use of var

* tls

* try -and

* Try different tls set

* Try different speech marks

* Try different speech marks

* Try different speech marks

* Find out status

* Try without trim

* Look for different approach

* Use job base name

* Try remove speech marks

* Try moving outside of same command

* Reorder tests to fail fast

* Try with speech marks

* Try with speech marks

* Try on same line

* Remove incorrect key

* Try with my email

* Readd windows tests and move post out

* Remove failure

* Remove failfast flag

* Split across multipl lines

* Test split across multiple lines

* Remove errors
  • Loading branch information
JamesKingWork authored Apr 22, 2020
1 parent 9f85823 commit 542b772
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ def setGitHubBuildStatus(String status, String message, String context) {
}
}

def getGitCommitAuthorEmail() {
script {
withCredentials([string(credentialsId: 'Euphonic_GitHub_API_Token',
variable: 'api_token')]) {
if(isUnix()) {
return sh(
script: """
commit_url="\$(\\
curl -s -H "Authorization: token ${api_token}" \\
--request GET https://api.github.com/repos/pace-neutrons/Euphonic/git/ref/heads/${env.JOB_BASE_NAME} \\
| jq ".object.url" | tr -d '"'\\
)" &&
echo "\$(\\
curl -s -H "Authorization: token ${api_token}" \\
--request GET \$commit_url | jq '.author.email' | tr -d '"'\\
)"
""",
returnStdout: true
)
} else {
error("Cannot get commit author in Windows")
}
}
}
}

pipeline {

agent none
Expand Down Expand Up @@ -169,7 +195,6 @@ pipeline {
steps {
setGitHubBuildStatus("pending", "Starting", "Windows")
echo "Branch: ${env.JOB_BASE_NAME}"
bat 'set'
}
}

Expand Down Expand Up @@ -232,4 +257,19 @@ pipeline {
}
}
}

post {
unsuccessful {
node("sl7") {
script {
def email = getGitCommitAuthorEmail()
mail (
to: "$email",
subject: "Failed pipeline: ${env.JOB_BASE_NAME}",
body: "See ${env.BUILD_URL}"
)
}
}
}
}
}

0 comments on commit 542b772

Please sign in to comment.