forked from PAIA-Playful-AI-Arena/swimming_squid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
60 lines (56 loc) · 1.82 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
pipeline {
agent {
label 'HP_Docker_Agent'
}
environment {
game = 'swimming_squid_battle'
REPO = "https://github.com/PAIA-Playful-AI-Arena/${game}.git"
registry = 'paiatech'
}
stages {
stage('get the latest tag'){
steps{
script {
def latestTag = sh(
script: 'git describe --tags `git rev-list --tags --max-count=1`',
returnStdout: true
).trim()
echo "Latest tag: ${latestTag}"
def fullBranch = env.GIT_BRANCH
echo "full branch: ${fullBranch}"
// Extract the branch name
def branch = fullBranch.replaceFirst('^origin/', '')
echo "Current branch by replace: ${branch}"
// Store the latest tag in an environment variable
env.tag = latestTag
env.branch = branch
}
}
}
stage('build and deploy') {
steps {
echo 'build'
script {
sh "docker buildx ls"
if (branch == 'main' && env.tag) {
sh """docker buildx build --builder=mybuilder --platform linux/amd64 \
-t ${env.registry}/${game}:${env.tag} \
-t ${env.registry}/${game}:${env.branch} \
-f ./Dockerfile . --push
"""
}else{
sh """docker buildx build --builder=mybuilder --platform linux/amd64 \
-t ${env.registry}/${game}:${env.branch} \
-f ./Dockerfile . --push
"""
}
}
}
}
stage('finish') {
steps {
echo 'finish'
}
}
}
}