-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
41 lines (36 loc) · 1.38 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
node {
gitrepo = checkout scm
gitBranch = gitrepo.GIT_BRANCH
try {
stage('checkout'){
checkout scm
}
if (gitBranch == 'origin/staging'){
stage('updating staging server'){
withCredentials([
sshUserPrivateKey(credentialsId: 'staging-ssh-cred', keyFileVariable: 'SSHPASS'),
file(credentialsId: 'git-cred', variable: 'GITCRED')]){
ansiblePlaybook become: true, colorized: true, credentialsId: 'staging-ssh-cred', disableHostKeyChecking: true, inventory: './ansible-code/inventory',limit: 'stag', extras: '-e branch="staging" -e keyfile="${GITCRED}"', playbook: './ansible-code/bitclone.yml'
}
}
}
if (gitBranch == 'origin/master'){
stage('updating production server'){
withCredentials([
sshUserPrivateKey(credentialsId: 'staging-ssh-cred', keyFileVariable: 'SSHPASS'),
file(credentialsId: 'git-cred', variable: 'GITCRED')]){
ansiblePlaybook become: true, colorized: true, credentialsId: 'staging-ssh-cred', disableHostKeyChecking: true, inventory: './ansible-code/inventory',limit: 'prod', extras: '-e branch="master" -e keyfile="${GITCRED}"', playbook: './ansible-code/bitclone.yml'
}
}
}
}
catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
throw e
}
finally {
echo "Current Jenkins pipeline name: $env.JOB_NAME"
echo "Current branch: $gitrepo.GIT_BRANCH"
}
}