-
Notifications
You must be signed in to change notification settings - Fork 40
/
Scripted-SQ-Jenkinsfile
48 lines (39 loc) · 1.76 KB
/
Scripted-SQ-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
node {
withEnv([
// You need to specify 3 required environment variables and your bluemix credentials first, they are going to be used for the following IBM Cloud DevOps steps
'IBM_CLOUD_DEVOPS_ORG=dlatest',
'IBM_CLOUD_DEVOPS_APP_NAME=Weather-V1-Scripted',
'IBM_CLOUD_DEVOPS_TOOLCHAIN_ID=1320cec1-daaa-4b63-bf06-7001364865d2',
'IBM_CLOUD_DEVOPS_WEBHOOK_URL=WEBHOOK_URL_PLACEHOLDER'
]) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'BM_CRED',
usernameVariable: 'IBM_CLOUD_DEVOPS_CREDS_USR', passwordVariable: 'IBM_CLOUD_DEVOPS_CREDS_PSW']]) {
stage('SCM') {
git 'https://github.com/ccox-IBM/simple-toolchain-1488583960040.git';
}
stage('SonarQube analysis') {
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'Default SQ Scanner';
withSonarQubeEnv('Default SQ Server') {
env.SQ_HOSTNAME = SONAR_HOST_URL;
env.SQ_AUTHENTICATION_TOKEN = SONAR_AUTH_TOKEN;
env.SQ_PROJECT_KEY = "simple-toolchain-1488583960040";
sh "${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=${SQ_PROJECT_KEY} \
-Dsonar.sources=. \
-Dsonar.organization=ccox-ibm-github";
//save host and auth token used to configure the SQ tool
}
}
stage("Quality Gate") {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate(); // Reuse taskId previously collected by withSonarQubeEnv
publishSQResults SQHostURL: "${SQ_HOSTNAME}", SQAuthToken: "${SQ_AUTHENTICATION_TOKEN}", SQProjectKey: "${SQ_PROJECT_KEY}"
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
}