2023-02-01 11:07:00 +00:00
|
|
|
def label = "worker-${UUID.randomUUID().toString()}"
|
|
|
|
|
|
|
|
podTemplate(
|
2023-02-01 11:08:12 +00:00
|
|
|
label: label,
|
2023-02-01 11:07:00 +00:00
|
|
|
containers: [
|
|
|
|
containerTemplate(
|
|
|
|
name: 'gradle',
|
|
|
|
image: 'gradle:7.6.0-jdk11',
|
|
|
|
command: 'sleep',
|
|
|
|
args: '30d'
|
2023-02-01 11:17:55 +00:00
|
|
|
),
|
|
|
|
containerTemplate(
|
|
|
|
name: 'docker',
|
|
|
|
image: 'docker:latest',
|
|
|
|
command: 'cat',
|
|
|
|
ttyEnabled: true
|
|
|
|
),
|
|
|
|
containerTemplate(
|
|
|
|
name: 'kubectl',
|
|
|
|
image: 'bitnami/kubectl:latest',
|
|
|
|
command: 'cat',
|
|
|
|
ttyEnabled: true
|
|
|
|
),
|
|
|
|
containerTemplate(
|
|
|
|
name: 'helm',
|
|
|
|
image: 'alpine/helm:latest',
|
|
|
|
command: 'cat',
|
|
|
|
ttyEnabled: true
|
2023-02-01 09:17:31 +00:00
|
|
|
)
|
2023-02-01 11:07:00 +00:00
|
|
|
],
|
|
|
|
volumes: [
|
2023-02-01 11:17:55 +00:00
|
|
|
hostPathVolume(mountPath: '/home/gradle/.gradle', hostPath: '/tmp/jenkins/.gradle'),
|
|
|
|
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
|
2023-02-01 11:07:00 +00:00
|
|
|
]
|
|
|
|
)
|
2023-02-01 14:44:31 +00:00
|
|
|
|
2023-02-01 11:07:00 +00:00
|
|
|
{
|
|
|
|
node(label) {
|
|
|
|
def myRepo = checkout scm
|
|
|
|
def gitCommit = myRepo.GIT_COMMIT
|
|
|
|
def gitBranch = myRepo.GIT_BRANCH
|
|
|
|
def shortGitCommit = "${gitCommit[0..10]}"
|
|
|
|
def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)
|
2023-02-01 23:18:41 +00:00
|
|
|
def dockerRegistryUrl = "harbor.loafle.net"
|
2023-02-01 08:34:23 +00:00
|
|
|
|
2023-02-01 11:07:00 +00:00
|
|
|
stage('Test') {
|
|
|
|
try {
|
|
|
|
container('gradle') {
|
2023-02-01 23:47:29 +00:00
|
|
|
def projectName = sh(returnStdout: true, script: "gradle -q projectName").trim()
|
|
|
|
def projectVersion = sh(returnStdout: true, script: "gradle -q projectVersion").trim()
|
|
|
|
env.PROJECT_NAME = projectName
|
|
|
|
env.PROJECT_VERSION = projectVersion
|
|
|
|
|
2023-02-01 22:54:42 +00:00
|
|
|
sh """
|
|
|
|
pwd
|
|
|
|
echo "GIT_BRANCH=${gitBranch}" >> /etc/environment
|
|
|
|
echo "GIT_COMMIT=${gitCommit}" >> /etc/environment
|
|
|
|
gradle test
|
|
|
|
"""
|
2023-02-01 08:18:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-01 11:07:00 +00:00
|
|
|
catch (exc) {
|
|
|
|
println "Failed to test - ${currentBuild.fullDisplayName}"
|
|
|
|
throw(exc)
|
|
|
|
}
|
|
|
|
}
|
2023-02-01 14:11:40 +00:00
|
|
|
|
2023-02-01 11:07:00 +00:00
|
|
|
stage('Build') {
|
|
|
|
container('gradle') {
|
|
|
|
sh "gradle build"
|
|
|
|
}
|
2023-02-01 07:26:49 +00:00
|
|
|
}
|
2023-02-01 11:17:55 +00:00
|
|
|
|
2023-02-01 14:11:40 +00:00
|
|
|
stage('Create Docker images') {
|
|
|
|
container('docker') {
|
|
|
|
withCredentials([[$class: 'UsernamePasswordMultiBinding',
|
|
|
|
credentialsId: 'harbor.loafle.net',
|
|
|
|
usernameVariable: 'HARBOR_USER',
|
|
|
|
passwordVariable: 'HARBOR_PASSWORD']]) {
|
|
|
|
sh """
|
2023-02-01 23:24:38 +00:00
|
|
|
docker login -u "${HARBOR_USER}" -p "${HARBOR_PASSWORD}" ${dockerRegistryUrl}
|
2023-02-01 23:36:14 +00:00
|
|
|
docker build -t ${dockerRegistryUrl}/prototype/${env.PROJECT_NAME}:${env.PROJECT_VERSION} --build-arg PROJECT_NAME=${env.PROJECT_NAME} --build-arg PROJECT_VERSION=${env.PROJECT_VERSION} .
|
|
|
|
docker push ${dockerRegistryUrl}/prototype/${env.PROJECT_NAME}:${env.PROJECT_VERSION}
|
2023-02-01 14:11:40 +00:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-31 13:42:28 +00:00
|
|
|
}
|
2023-02-01 09:48:49 +00:00
|
|
|
}
|