forked from broadinstitute/dockerized_mts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjenkinsfile
82 lines (74 loc) · 2.23 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
import groovy.json.JsonSlurper
REPO="prismcmap"
SRC_TAG="latest"
DEST_TAG="production"
def DOCKER_NAMES=[
"assemble-db",
"batch-correct-module",
"biomarker-module",
"collate",
"csv2json",
"deal",
"depmap_versions",
"drc-module",
"extract-biomarker",
"landing",
"lfc-module",
"merge-csvs",
"norm-module",
"pivot",
"pivot_splits",
"register-mts",
"reports",
"qc-screen",
"split",
"stack"
]
def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
def takeFromHash = 12
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
// def isRef = head.length > 1 // ref: refs/heads/master
if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
}
def parallelStagesMap = DOCKER_NAMES.collectEntries {
["${it}" : generateStage(it,getCheckedOutGitCommitHash())]
}
def generateStage(job,hash) {
return {
stage("stage: ${job}") {
sh script: "docker pull ${REPO}/${job}:${SRC_TAG}"
sh script: "docker tag $REPO/${job}:${SRC_TAG} ${REPO}/${job}:${DEST_TAG} ${REPO}/${job}:${hash}"
sh script: "docker push ${REPO}/${job}:${DEST_TAG}"
}
}
}
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS= credentials('dockerhub-cred-jasiedu')
}
stages {
stage('Login to Docker Hub') {
steps{
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | sudo docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
echo 'Login Completed'
}
}
stage('parallel stage') {
steps {
script {
parallel parallelStagesMap
}
}
}
}
}