This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Jenkinsfile
50 lines (40 loc) · 2.48 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
/*
This pipeline is used to send a webhook from the Developer Jenkins master to the Managed Platform Jenkins master to trigger
the CI pipeline for this project.
This pipeline expects to be executed via the GitHub Pull Request Builder Trigger and will explicitly fail if the required
parameters are not set.
*/
@Library('RedHatDevelopersPipelineUtils')
import com.redhat.developer.pr.*
import com.redhat.developer.mp.*
node {
timeout(120) {
stage("Sanity Check") {
if(!env.ghprbPullId) {
error "Cannot locate expected environment variable 'ghprbPullId'. Has this been triggered by the Git Hub Pull Request Builder?"
}
if(!env.ghprbActualCommit) {
error "Cannot locate expected environment variable 'ghprbActualCommit'. Has this been triggered by the Git Hub Pull Request Builder?"
}
}
def cause = "${env.ghprbActualCommit}-${env.BUILD_NUMBER}"
def context = env.ghprbCommentBody ? env.ghprbCommentBody.toString().trim() : ""
def credentials = [
usernamePassword(credentialsId: 'developers-redhat-com-automated-api-token', passwordVariable: 'JENKINS_USER_PASSWORD', usernameVariable: 'JENKINS_USER'),
usernamePassword(credentialsId: 'redhat-developer-ci-github-api-token', passwordVariable: 'GITHUB_USER_PASSWORD', usernameVariable: 'GITHUB_USER')
]
withCredentials(credentials) {
/*
Firstly trigger the job on jenkins.paas.redhat.com by sending a web-hook with the ID of the pull request that we're building and the cause
defined as the current HEAD reference of the PR branch and then the current build number
*/
def jenkinsJob = "https://jenkins.paas.redhat.com/generic-webhook-trigger/invoke?token=rhdp-pr-build"
scheduleMpBuild(pullRequestId: "${env.ghprbPullId}", cause: cause, jenkinsJob: jenkinsJob, jenkinsUser: env.JENKINS_USER, jenkinsPassword: env.JENKINS_USER_PASSWORD, context: context)
/*
And then we wait for that build to appear to be running on jenkins.paas.redhat.com. In particular we're waiting to see the above cause appear on the list
of statuses for our pull request.
*/
waitForMpBuildToStart(gitRepository: 'redhat-developer/developers.redhat.com', pullRequestRef: "${env.ghprbActualCommit}", cause: cause, gitApiCredentials: env.GITHUB_USER_PASSWORD)
}
}
}