-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
71 lines (71 loc) · 2.73 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
pipeline {
agent any
environment {
reg_pw = credentials('Dockerhub PW')
environ = sh (
script: '''
echo $BRANCH_NAME|sed 's@origin/@@g'
''',
returnStdout: true
).trim()
}
stages {
stage('Build') {
environment {
environ = sh (
script: '''
echo $BRANCH_NAME|sed 's@origin/@@g'
''',
returnStdout: true
).trim()
tag = sh (
script: '''
if [ "${environ}" = "dev" ]; then
echo "staging"
elif [ "${environ}" = "master" ]; then
echo "latest"
else
echo "nobuild"
fi
''',
returnStdout: true
).trim()
}
steps {
script {
if( "${tag}" == "nobuild" ) {
currentBuild.getRawBuild().getExecutor().interrupt(Result.ABORTED)
print("Ignoring branch ${tag}")
sleep(1)
}
}
git url: 'https://github.com/Native-Planet/anchor-source.git',
credentialsId: 'Github token',
branch: "${environ}"
sh "docker login -u nativeplanet -p $reg_pw docker.io"
dir("${env.WORKSPACE}/"){
sh (
script: '''
if $(docker buildx create --name xbuilder);
then
echo "builder created"
else
echo "builder exists"
fi
docker buildx use xbuilder
docker buildx build --push --tag nativeplanet/anchor-api:${tag} --platform linux/amd64,linux/arm64 --no-cache ./api/
docker buildx build --push --tag nativeplanet/anchor-wg:${tag} --platform linux/amd64,linux/arm64 --no-cache ./wg/
docker buildx build --push --tag nativeplanet/anchor-caddy:${tag} --platform linux/amd64,linux/arm64 --no-cache ./caddy/
''',
returnStdout: true
)
}
}
}
}
post {
always {
cleanWs deleteDirs: true, notFailBuild: true
}
}
}