-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
60 lines (53 loc) · 1.75 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pipeline {
agent any
environment {
COMMIT_MESSAGE = """${sh(
returnStdout: true,
script: "git --no-pager log --format='medium' -1 ${GIT_COMMIT}"
)}"""
GALAXY_REPO = "vermilion-tech ansible-role-ubuntu-base"
}
stages {
stage('Notify Slack') {
steps {
slackSend(color: '#000000', message: "Build Started - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\n```${env.COMMIT_MESSAGE}```")
}
}
stage('Lint Ansible Role') {
agent { docker { image 'williamyeh/ansible:ubuntu18.04'} }
steps {
sh 'pip install ansible-lint'
script {
LINT_OUTPUT = sh(script: "ansible-lint . || true", returnStdout: true)
}
slackSend(color: '#e987f1', message: "Ansible Lint\n```\n${LINT_OUTPUT}\n```")
}
}
stage('Import Ansible Role') {
when {
anyOf {
branch 'master';
branch 'development'
}
}
agent { docker { image 'williamyeh/ansible:ubuntu18.04'} }
steps {
withCredentials([string(credentialsId: "ansible-galaxy-pat", variable: "GITHUB_PAT")]) {
sh 'ansible-galaxy login --github-token $GITHUB_PAT'
script {
IMPORT_OUTPUT = sh(script: "ansible-galaxy import --branch ${GIT_BRANCH} ${GALAXY_REPO}", returnStdout: true)
}
}
slackSend(color: '#d577dd', message: "Ansible-Galaxy Role Imported\n```${IMPORT_OUTPUT}```")
}
}
}
post {
failure {
slackSend (color: '#FF0000', message: "Build Failed! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
success {
slackSend (color: '#00FF00', message: "Success! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
}
}