Merge pull request #158 from sartography/ci/add-jenkinsfile

ci: add basic jenkinsfile for building Docker images
This commit is contained in:
Kevin Burnett 2023-03-01 08:01:23 -08:00 committed by GitHub
commit 27446e7a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 70 additions and 0 deletions

70
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,70 @@
pipeline {
agent { label 'linux' }
options {
timestamps()
timeout(time: 20, unit: 'MINUTES')
disableConcurrentBuilds()
buildDiscarder(logRotator(
numToKeepStr: '10',
daysToKeepStr: '30',
))
}
parameters {
string(
name: 'COMPONENT',
description: 'Name of component to build.',
defaultValue: params.COMPONENT ?: 'backend'
)
string(
name: 'DOCKER_TAG',
description: 'Name of Docker tag to push. Chose wisely.',
defaultValue: params.DOCKER_TAG ?: 'latest',
)
string(
name: 'DOCKER_NAME',
description: 'Name of Docker image to push.',
defaultValue: params.DOCKER_NAME ?: 'ghcr.io/sartography/spiffworkflow-backend',
)
string(
name: 'DOCKER_CRED_ID',
description: 'ID of Jenkins credential for Docker registry.',
defaultValue: params.DOCKER_CRED_ID ?: 'MISSING'
)
booleanParam(
name: 'PUBLISH',
description: 'Publish built Docker images.',
defaultValue: params.PUBLISH ?: false
)
}
stages {
stage('Build') {
steps { script {
dir("spiffworkflow-${params.COMPONENT}") {
image = docker.build(
"${params.DOCKER_NAME}:${env.GIT_COMMIT.take(8)}",
"--label=commit='${env.GIT_COMMIT.take(8)}' ."
)
}
} }
}
stage('Push') {
when { expression {
params.PUBLISH && params.DOCKER_CRED_ID != ''
} }
steps { script {
withDockerRegistry([credentialsId: params.DOCKER_CRED_ID, url: ""]) {
image.push()
image.push(env.DOCKER_TAG)
}
} }
}
} // stages
post {
always { sh 'docker image prune -f' }
cleanup { cleanWs() }
} // post
} // pipeline