forked from cloudbees-core-cd-workshop/pipeline-library
-
Notifications
You must be signed in to change notification settings - Fork 120
/
Jenkinsfile
113 lines (110 loc) · 4.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
library "pipeline-library@$BRANCH_NAME"
def gitHubCredId = 'field-workshops-github-app'
pipeline {
agent none
options {
timeout(time: 20, unit: 'MINUTES')
disableConcurrentBuilds()
}
stages {
stage('GitHub Tests') {
agent {label 'default-jnlp' }
stages {
stage('GitHub Setup') {
steps {
withCredentials([usernamePassword(credentialsId: "${gitHubCredId}",
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_ACCESS_TOKEN')]) {
sh(script: """
curl -H 'Accept: application/vnd.github.antiope-preview+json' \
-H 'authorization: Bearer ${GITHUB_ACCESS_TOKEN}' \
-H "Accept: application/vnd.github.baptiste-preview+json" \
https://api.github.com/repos/cloudbees-days/simple-java-maven-app/generate \
--data '{"owner":"cloudbees-days","name":"${BUILD_TAG}"}'
""")
waitUntil {
script {
def status = sh (script: """
curl -s -o /dev/null -w '%{http_code}' \
-H 'authorization: Bearer ${GITHUB_ACCESS_TOKEN}' \
-H 'Accept: application/vnd.github.baptiste-preview+json' \
https://api.github.com/repos/cloudbees-days/${BUILD_TAG}/git/ref/heads/master
""", returnStdout: true)
echo "after creating ${BUILD_TAG} repo - returned status: ${status}"
return (status=="200")
}
}
sh(script: """
mkdir -p pipeline-library-test
cd pipeline-library-test
git init
git config user.email "[email protected]"
git config user.name "CloudBees CI Bot"
git remote add origin https://x-access-token:${GITHUB_ACCESS_TOKEN}@github.com/cloudbees-days/${BUILD_TAG}.git
git pull origin master
git fetch
git checkout -B test-branch
cp example.cloudbees-ci.yml cloudbees-ci.yml
git add cloudbees-ci.yml
git commit -a -m 'adding marker file'
git push -u origin test-branch
echo "create pull request"
curl -H 'Accept: application/vnd.github.antiope-preview+json' \
-H 'authorization: Bearer ${GITHUB_ACCESS_TOKEN}' \
--data '{"title":"add marker file","head":"test-branch","base":"master"}' \
https://api.github.com/repos/cloudbees-days/${BUILD_TAG}/pulls
""")
}
script {
def commentId = gitHubComment(message: "test pr comment", credId: gitHubCredId, issueId: 1, repoOwner: 'cloudbees-days', repo: BUILD_TAG)
withCredentials([usernamePassword(credentialsId: "${gitHubCredId}",
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_ACCESS_TOKEN')]) {
def actualCommentBody = sh(script: """
curl \
-H "Accept: application/vnd.github.v3+json" \
-H 'authorization: Bearer ${GITHUB_ACCESS_TOKEN}' \
https://api.github.com/repos/cloudbees-days/${BUILD_TAG}/issues/comments/${commentId} \
| jq -r '.body' | tr -d '\n'
""", returnStdout: true)
echo "actualCommentBody: ${actualCommentBody}"
if(!actualCommentBody.equals("test pr comment")) {
error "Failed PR Comment Test"
}
}
}
}
}
stage('Repo Files') {
steps {
dir('pipeline-library-test') {
customYamlProps()
}
script {
if(!lineCoverage.equals("100")) {
error "Failed customYamlProps test"
}
}
}
}
}
}
}
post {
always {
node('default-jnlp') {
withCredentials([usernamePassword(credentialsId: "${gitHubCredId}",
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_ACCESS_TOKEN')]) {
sh(script: """
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H 'authorization: Bearer ${GITHUB_ACCESS_TOKEN}' \
https://api.github.com/repos/cloudbees-days/${BUILD_TAG}
""")
}
}
}
}
}