Skip to content

Commit 9bb0322

Browse files
committed
Use internal debian image, improve branch-based versioning
1 parent aae9caf commit 9bb0322

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

jenkins/JenkinsFile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def projectProperties = [
2626
pipelineTriggers(pipeline_triggers),
2727
[$class: 'BuildDiscarderProperty',strategy: [$class: 'LogRotator', numToKeepStr: '50']],
2828
parameters ([
29-
string(name:'BASE_IMAGE', defaultValue:'debian:12-slim', description: 'eg. 1.0.0.1757'),
29+
string(name:'BASE_IMAGE', defaultValue:'docker-virtual-wap.artifactorylbj.it.keysight.com/wap-base-debian:12.8-slim', description: 'docker-virtual-wap.artifactorylbj.it.keysight.com/wap-base-debian:12.8-slim'),
3030
booleanParam(name:'publish_pypi', defaultValue:false, description: 'If true, the build will be published to the public PyPI repos. Only works on release/ branches.')
3131
]),
3232
]
@@ -37,20 +37,23 @@ def do_publish = params.publish_pypi
3737

3838
@NonCPS
3939
boolean setDisplayVersion(publish) {
40+
branch_sanitized = branch.replaceAll('-', '.').replaceAll('_', '.')
4041
def matcher = Pattern.compile("^release%2F([0-9]+)\\.([0-9]+)\$").matcher(branch)
4142
if (matcher.matches()) {
42-
build_number = "dev${env.BUILD_NUMBER}"
43+
build_number = "dev${env.BUILD_NUMBER}+${branch_sanitized}"
4344
if (publish) {
4445
build_number = "${env.BUILD_NUMBER}"
4546
}
46-
env.VERSION = "${matcher.group(1).toString()}.${matcher.group(2).toString()}.${build_number}"
47+
env.PIP_VERSION = "${matcher.group(1).toString()}.${matcher.group(2).toString()}.${build_number}"
48+
env.DOCKER_VERSION = env.PIP_VERSION.replaceAll('\\+', '-')
4749
} else if (branch.startsWith("release%2F")) {
4850
throw new Exception("Unexpected release branch format ${branch}, expected 'release%2fNUMBER.NUMBER'")
4951
} else {
50-
env.VERSION = "0.0.dev${env.BUILD_NUMBER}"
52+
env.PIP_VERSION = "0.0.dev${env.BUILD_NUMBER}+${branch_sanitized}"
53+
env.DOCKER_VERSION = env.PIP_VERSION.replaceAll('\\+', '-')
5154
publish = false
5255
}
53-
currentBuild.displayName = env.VERSION
56+
currentBuild.displayName = env.PIP_VERSION
5457
return publish
5558
}
5659

@@ -71,15 +74,15 @@ node('wap') {
7174
sh('''
7275
docker build -f docker/Dockerfile \
7376
--build-arg base_image="$BASE_IMAGE" \
74-
--build-arg VERSION="$VERSION" \
75-
-t cyperf-api-wrapper-build:$VERSION \
77+
--build-arg VERSION="$PIP_VERSION" \
78+
-t cyperf-api-wrapper-build:$DOCKER_VERSION \
7679
.
7780
''')
7881
}
7982
stage('Run tests') {
8083
sh('''
8184
docker run --rm \
82-
cyperf-api-wrapper-build:$VERSION \
85+
cyperf-api-wrapper-build:$DOCKER_VERSION \
8386
/cyperf-api-wrapper-build/test.sh /build/py3
8487
''')
8588
}
@@ -92,7 +95,7 @@ node('wap') {
9295
docker run --rm \
9396
--env TWINE_USERNAME="$ARTIFACTORY_USERNAME" \
9497
--env TWINE_PASSWORD="$ARTIFACTORY_PASSWORD" \
95-
cyperf-api-wrapper-build:$VERSION \
98+
cyperf-api-wrapper-build:$DOCKER_VERSION \
9699
/cyperf-api-wrapper-build/publish.sh /build/py3 "--repository artifactory"
97100
''')
98101
}
@@ -106,15 +109,15 @@ node('wap') {
106109
docker run --rm \
107110
--env TWINE_USERNAME="__token__" \
108111
--env TWINE_PASSWORD="$PYPI_API_TOKEN" \
109-
cyperf-api-wrapper-build:$VERSION \
112+
cyperf-api-wrapper-build:$DOCKER_VERSION \
110113
/cyperf-api-wrapper-build/publish.sh /build/py3
111114
''')
112115
}
113116
}
114117
}
115118
stage('Cleanup') {
116119
sh('''
117-
docker rmi cyperf-api-wrapper-build:$VERSION
120+
docker rmi cyperf-api-wrapper-build:$DOCKER_VERSION
118121
''')
119122
}
120123
}

0 commit comments

Comments
 (0)