forked from ibmdevopsinsights/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScripted-Jenkinsfile
More file actions
56 lines (50 loc) · 2.7 KB
/
Scripted-Jenkinsfile
File metadata and controls
56 lines (50 loc) · 2.7 KB
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
#!groovy
node {
git url: 'https://github.com/uparulekar/DevOpsInsightsShellTutorial.git'
withEnv([
// Three environment variables are needed for DevOps Insights
// IBM_CLOUD_DEVOPS_APP_NAME -> This is the name of the application that shows up in the dashboard
// IBM_CLOUD_DEVOPS_TOOLCHAIN_ID -> This is your toolchain id, for this tutorial the value for it is set in the Jenkins configuration page
// IBM_CLOUD_DEVOPS_API_KEY -> This is the api key for your account that also has access to the toolchain, the value for this is specified in Jenkins credentials.
'IBM_CLOUD_DEVOPS_APP_NAME=Weather-App-Scripted',
]) {
withCredentials([string(credentialsId: 'YOUR_API_KEY_ID', variable: 'IBM_CLOUD_DEVOPS_API_KEY')]) {
stage('Build') {
try {
sh '''
echo "Build...."
'''
// use "publishBuildRecord" method to publish build record
publishBuildRecord gitBranch: "master", gitCommit: "123234345", gitRepo: "https://test-iam-1", result:"SUCCESS"
}
catch (Exception e) {
publishBuildRecord gitBranch: "master", gitCommit: "123234345", gitRepo: "https://test-iam-1", result:"FAIL"
}
}
stage('Upload Unit Test and Code Coverage') {
sh '''
echo "Upload test results...."
'''
// use "publishTestResult" method to publish test result
publishTestResult type:'unittest', fileLocation: './mocha_pass.json'
publishTestResult type:'code', fileLocation: './istanbul_pass.json'
}
stage('Gate') {
// use "evaluateGate" method to leverage IBM Cloud DevOps gate
evaluateGate policy: 'FirstPolicy', forceDecision: 'true'
}
stage('Deploy') {
try {
sh '''
echo "Deploying...."
'''
// use "publishDeployRecord" method to publish test result
publishDeployRecord environment: "dev", appUrl: "https://test-iam-app-1", result:"SUCCESS"
}
catch (Exception e) {
publishDeployRecord environment: "dev", appUrl: "https://test-iam-app-1", result:"FAIL"
}
}
}
}
}