forked from networktocode/cicd-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
68 lines (68 loc) · 2.95 KB
/
Jenkinsfile
File metadata and controls
68 lines (68 loc) · 2.95 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
57
58
59
60
61
62
63
64
65
66
67
68
pipeline {
agent {
dockerfile {
filename 'Dockerfile'
args '--user root'
reuseNode true
}
}
stages {
stage('offline') {
steps {
script {
try {
githubNotify status: "PENDING", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
sh '''
if [ "${GITHUB_PR_STATE}" == "CLOSED" ]; then export inventory="prod_inventory" ; else export inventory="qa_inventory" ; fi
printenv
yamllint -d yamllint.yml .
ansible-playbook -i prod_inventory offline_data_checks.yml
ansible-playbook -i ${inventory} build_configurations.yml
'''
} catch(err) {
githubNotify status: "FAILURE", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
currentBuild.result = 'FAILED'
throw err
}
}
}
}
stage('push_config') {
steps {
script {
try {
githubNotify status: "PENDING", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
sh '''
if [ "${GITHUB_PR_STATE}" == "CLOSED" ]; then export inventory="prod_inventory" ; else export inventory="qa_inventory" ; fi
ansible-playbook -i ${inventory} push_updated_config.yml
'''
} catch(err) {
githubNotify status: "FAILURE", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
currentBuild.result = 'FAILED'
throw err
}
}
}
}
stage('post_deploy_tests') {
steps {
script {
try {
githubNotify status: "PENDING", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
sh '''
if [ "${GITHUB_PR_STATE}" == "CLOSED" ]; then export inventory="prod_inventory" ; else export inventory="qa_inventory" ; fi
ansible-playbook -i ${inventory} operational_checks.yml
'''
githubNotify status: "SUCCESS", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
} catch(err) {
githubNotify status: "FAILURE", sha: "${GITHUB_PR_HEAD_SHA}", description: "Build started...", credentialsId: "ntcteam", account: "networktocode", repo: "cicd-testing"
currentBuild.result = 'FAILED'
throw err
} finally {
sh "echo 'shell scripts to deploy to server...'"
}
}
}
}
}
}