-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (50 loc) · 1.86 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
properties([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '365',
artifactNumToKeepStr: '1000',
daysToKeepStr: '365',
numToKeepStr: '1000'
)),
disableConcurrentBuilds(), pipelineTriggers([]
)])
def runCommand(String command) {
return (sh(returnStdout: true, script: command)).trim()
}
def repositoryName = 'istvan32/php-server'
node {
stage('checkout') {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: true,
extensions: [
[$class: 'LocalBranch', localBranch: env.BRANCH_NAME],
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'SubmoduleOption', parentCredentials: true]
],
userRemoteConfigs: scm.userRemoteConfigs
])
}
stage('build') {
def taggedVersion = runCommand('git tag --contains HEAD')
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'password', usernameVariable: 'username')]) {
sh 'docker login -u $username -p $password'
}
sh 'mkdir -p docker-entrypoint.d'
try {
sh 'docker run --privileged --rm tonistiigi/binfmt --install arm64,arm'
sh 'docker buildx create --use'
if (taggedVersion) {
sh "docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ${repositoryName}:${taggedVersion} ."
} else {
sh "docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ${repositoryName} ."
}
} catch (error) {
throw error;
} finally {
sh 'docker buildx prune -af'
sh 'docker buildx stop'
}
}
}