forked from PolusAI/image-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
75 lines (73 loc) · 3.46 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
pipeline {
agent {
node { label 'linux && build && aws' }
}
environment {
PROJECT_URL = 'https://github.com/polusai/polus-plugins'
}
triggers {
pollSCM('H/5 * * * *')
}
stages {
stage('Build Version') {
steps{
script {
BUILD_VERSION_GENERATED = VersionNumber(
versionNumberString: 'v${BUILD_YEAR, XX}.${BUILD_MONTH, XX}${BUILD_DAY, XX}.${BUILDS_TODAY}',
projectStartDate: '1970-01-01',
skipFailedBuilds: false)
currentBuild.displayName = BUILD_VERSION_GENERATED
env.BUILD_VERSION = BUILD_VERSION_GENERATED
}
}
}
stage('Checkout source code') {
steps {
cleanWs()
checkout scm
}
}
stage('Build Docker images') {
steps {
script {
configFileProvider([configFile(fileId: 'update-docker-description', targetLocation: 'update.sh')]) {
// List all directories, each directory contains a plugin
def pluginDirectories = """${sh (
script: "ls -d */",
returnStdout: true
)}"""
// Iterate over each plugin directory
pluginDirectories.split().each { repo ->
// Truncate hanging "/" for each directory
def pluginName = repo.getAt(0..(repo.length() - 2))
// Check if VERSION file for each plugin file has changed
def isChanged = "0"
if (env.GIT_PREVIOUS_SUCCESSFUL_COMMIT) {
isChanged = """${sh (
script: "git diff --name-only ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} ${GIT_COMMIT} | grep ${pluginName}/VERSION",
returnStatus: true
)}"""
}
if (isChanged == "0" && pluginName != "utils") {
dir("${WORKSPACE}/${pluginName}") {
def dockerVersion = readFile(file: 'VERSION').trim()
docker.withRegistry('https://registry-1.docker.io/v2/', 'f16c74f9-0a60-4882-b6fd-bec3b0136b84') {
def image = docker.build("labshare/${pluginName}", '--no-cache ./')
image.push()
image.push(dockerVersion)
}
env.PROJECT_NAME = "${pluginName}"
env.FULL_DESC = readFile(file: 'README.md')
env.BRIEF_DESC = "${PROJECT_URL}/tree/master/${PROJECT_NAME}"
}
withCredentials([usernamePassword(credentialsId: 'f16c74f9-0a60-4882-b6fd-bec3b0136b84', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PW')]) {
sh "sh ./update.sh"
}
}
}
}
}
}
}
}
}