forked from GetDKAN/dkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
119 lines (113 loc) · 3.97 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import groovy.json.JsonOutput
pipeline {
agent any
environment {
PATH = "$WORKSPACE/dkan-tools/bin:$PATH"
USER = 'jenkins'
DKTL_SLUG = "dkan-qa-$CHANGE_ID"
DKTL_TRAEFIK = "proxy"
WEB_DOMAIN = "ci.civicactions.net"
DKAN_REPO = 'https://github.com/GetDKAN/dkan.git'
DKTL_REPO = 'https://github.com/GetDKAN/dkan-tools.git'
DKTL_DIRECTORY = "$WORKSPACE/dkan-tools"
DKTL_NO_PROXY = "1"
TARGET_URL = ""
}
stages {
stage ('Clean-Preclean') {
when { changeRequest(); }
steps {
script {
sh '''
echo "If exist...remove containers and network for qa_$CHANGE_ID"
qa_container_ids=`docker ps -f name=$DKTL_SLUG -q`
qa_network_id=`docker network ls -f name=$DKTL_SLUG -q`
if [ -n "$qa_container_ids" ]
then
for i in $qa_container_ids
do
docker container stop $i
docker container rm $i
done
docker network disconnect $qa_network_id proxy || true
docker network rm $qa_network_id
sudo rm -r $WORKSPACE/*
fi
'''
deleteDir()
}
}
}
stage ('Clone DKAN Repo') {
when { changeRequest(); }
steps {
dir ("projects/dkan") {
git url: DKAN_REPO, branch: "${env.CHANGE_BRANCH}"
}
}
}
stage ('Clone dkan-tools') {
when { changeRequest(); }
steps {
dir ("dkan-tools") {
git url: DKTL_REPO, branch: "dkan-qa-builder-no-proxy"
}
}
}
stage('Build QA Site') {
when { changeRequest(); }
steps {
script {
sh '''
cd projects
export DKTL_DIRECTORY="$WORKSPACE/dkan-tools"
echo $DKTL_DIRECTORY
dktl init --dkan-local
dktl demo
dktl drush user:password admin mayisnice
sudo chown -R 1000:docker $WORKSPACE/dkan-tools/vendor
curl -fI `dktl url`
'''
}
}
}
}
post {
always {
script {
sh '''
sudo chown -R 1000:docker $WORKSPACE
'''
}
}
success {
script {
gitCommitMessage = sh(returnStdout: true, script: 'git -C projects/dkan log -1 --pretty=%B || true').trim()
currentBuild.description = "${gitCommitMessage}"
def target_url = "http://$DKTL_SLUG.$WEB_DOMAIN"
setBuildStatus("QA site ready at ${target_url}", target_url, "success");
}
}
}
}
/**
* Report build status to github.
*
* @param message Message for status description
* @param target_url URL of the QA site we're building
* @param state State to report to Github (e.g. "success")
*/
void setBuildStatus(String message, String target_url, String state) {
withCredentials([string(credentialsId: 'dkanuploadassets',
variable: 'GITHUB_API_TOKEN')]) {
def url = "https://api.github.com/repos/getdkan/dkan/statuses/$GIT_COMMIT?access_token=${GITHUB_API_TOKEN}"
def data = [
target_url: target_url,
state: state,
description: message,
context: "continuous-integration/jenkins/qa-site"
]
def payload = JsonOutput.toJson(data)
sh "curl -X POST -H 'Content-Type: application/json' -d '${payload}' ${url}"
}
}