This repository has been archived by the owner on May 18, 2022. It is now read-only.
forked from zwalsh/button
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
55 lines (54 loc) · 1.52 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
pipeline {
agent any
environment {
GITHUB_TOKEN = credentials('github-personal-access-token')
}
stages {
stage('start') {
steps {
setBuildStatus('pending')
}
}
stage('test') {
steps {
sh './gradlew clean build'
}
}
stage('release') {
when {
expression { env.GIT_BRANCH == 'origin/main' }
}
steps {
sh "mkdir ~button/releases/$GIT_COMMIT"
sh "tar -xvf build/distributions/button.tar -C ~button/releases/$GIT_COMMIT"
}
}
}
post {
success {
echo 'Success!'
setBuildStatus('success')
}
unstable {
echo 'I am unstable :/'
setBuildStatus('failure')
}
failure {
echo 'I failed :('
setBuildStatus('failure')
}
always {
junit '**/build/test-results/test/TEST-*.xml'
}
}
}
void setBuildStatus(state) {
sh """
curl "https://api.GitHub.com/repos/zwalsh/button/statuses/$GIT_COMMIT" \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
-X POST \
-d '{\"state\": \"$state\",\"context\": \"continuous-integration/jenkins\",
\"description\": \"Jenkins\", \"target_url\": \"https://jenkins.zachwal.sh/job/button/$BUILD_NUMBER/console\"}'
"""
}