-
Notifications
You must be signed in to change notification settings - Fork 40
/
Demo-Jenkinsfile
104 lines (103 loc) · 4.34 KB
/
Demo-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
#!groovy
/*
This is an sample Jenkins file for the Weather App, which is a node.js application that has unit test, code coverage
and functional verification tests, deploy to staging and production environment and use IBM Cloud DevOps gate.
We use this as an example to use our plugin in the Jenkinsfile
Basically, you need to specify required 4 environment variables and then you will be able to use the 4 different methods
for the build/test/deploy stage and the gate
*/
pipeline {
agent any
environment {
// You need to specify 4 required environment variables first, they are going to be used for the following IBM Cloud DevOps steps
IBM_CLOUD_DEVOPS_CREDS = credentials('BLUEMIX_CREDENTIAL_ID')
IBM_CLOUD_DEVOPS_ORG = 'ORG_NAME_PLACEHOLDER'
IBM_CLOUD_DEVOPS_APP_NAME = 'APP_NAME_PLACEHOLDER'
IBM_CLOUD_DEVOPS_TOOLCHAIN_ID = 'TOOLCHAIN_ID_PLACEHOLDER'
GIT_REPO = 'https://github.com/open-toolchain/DemoDRA'
}
tools {
nodejs 'recent' // your nodeJS installation name in Jenkins
}
stages {
stage('SCM') {
steps {
deleteDir()
git "${GIT_REPO}"
}
}
stage('Build') {
environment {
// get git commit from Jenkins
GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
GIT_BRANCH = 'master'
}
steps {git
sh 'npm --version'
sh 'npm install'
sh 'grunt dev-setup --no-color'
}
// post build section to use "publishBuildRecord" method to publish build record
post {
success {
publishBuildRecord gitBranch: "${GIT_BRANCH}", gitCommit: "${GIT_COMMIT}", gitRepo: "${GIT_REPO}", result:"SUCCESS"
}
failure {
publishBuildRecord gitBranch: "${GIT_BRANCH}", gitCommit: "${GIT_COMMIT}", gitRepo: "${GIT_REPO}", result:"FAIL"
}
}
}
stage('Unit Test and Code Coverage') {
steps {
sh 'grunt dev-test-cov --no-color -f'
}
// post build section to use "publishTestResult" method to publish test result
post {
always {
publishTestResult type:'unittest', fileLocation: './mochatest.json'
publishTestResult type:'code', fileLocation: './tests/coverage/reports/coverage-summary.json'
}
}
}
stage('Deploy to Staging') {
steps {
// Push the Weather App to Bluemix, staging space
sh '''
echo "Deploying App to Staging"
'''
}
// post build section to use "publishDeployRecord" method to publish deploy record and notify OTC of stage status
post {
success {
publishDeployRecord environment: "STAGING", appUrl: "http://staging-${IBM_CLOUD_DEVOPS_APP_NAME}.mybluemix.net", result:"SUCCESS"
}
failure {
publishDeployRecord environment: "STAGING", appUrl: "http://staging-${IBM_CLOUD_DEVOPS_APP_NAME}.mybluemix.net", result:"FAIL"
}
}
}
stage('Gate') {
steps {
// use "evaluateGate" method to leverage IBM Cloud DevOps gate
evaluateGate policy: 'POLICY_NAME_PLACEHOLDER', forceDecision: 'true'
}
}
stage('Deploy to Prod') {
steps {
// Push the Weather App to Bluemix, production space
sh '''
echo "Deploying to Prod"
'''
}
// post build section to use "publishDeployRecord" method to publish deploy record and notify OTC of stage status
post {
success {
publishDeployRecord environment: "PRODUCTION", appUrl: "http://prod-${IBM_CLOUD_DEVOPS_APP_NAME}.mybluemix.net", result:"SUCCESS"
}
failure {
publishDeployRecord environment: "PRODUCTION", appUrl: "http://prod-${IBM_CLOUD_DEVOPS_APP_NAME}.mybluemix.net", result:"FAIL"
}
}
}
}
}