Skip to content

Commit

Permalink
chore: add conditional run to codepod ci
Browse files Browse the repository at this point in the history
  • Loading branch information
annleefores committed Dec 14, 2023
1 parent 960aa3c commit bb25502
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions server/codepod/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
def runEntirePipeline = true

pipeline {
agent {
kubernetes {
Expand Down Expand Up @@ -37,46 +39,82 @@ pipeline {
}

stages {
stage('Check for changes') {
steps {
script {
// list file changes in server/backend folder
def changedFiles = sh(script: 'git diff --name-only HEAD^ HEAD -- server/codepod', returnStdout: true).trim().split('\n').findAll { it.trim() }

println('Changed files: ' + changedFiles)

if (changedFiles.size() == 0) {
runEntirePipeline = false
} else {
println('File changes in server/codepod')
}
}
}
}

stage('sonarqube') {
steps{
container('sonarqube') {
when {
expression {
runEntirePipeline
}
}
steps {
container('sonarqube') {
withSonarQubeEnv(installationName: 'sq1') {
sh "/home/sonar-scanner-cli/bin/sonar-scanner -Dsonar.projectKey=kodiko-codepod -Dsonar.sources=server/codepod -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}"
}
sh "/home/sonar-scanner-cli/bin/sonar-scanner -Dsonar.projectKey=kodiko-codepod -Dsonar.sources=server/codepod -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}"
}
}
}
}

stage('quality gate') {
steps{
timeout(time: 6, unit: 'MINUTES') {
when {
expression {
runEntirePipeline
}
}
steps {
timeout(time: 6, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}

stage('get tag') {
steps{
stage('get tag') {
when {
expression {
runEntirePipeline
}
}
steps {
script {
def codepodVersion = sh(script: "git tag -l 'kodiko-backend-*' --sort='-version:refname' | head -n1 | awk -F'-' '{print \$3}'", returnStdout: true).trim()
echo "Current tag: ${codepodVersion}"

// Set the version as an environment variable
env.VERSION = codepodVersion

}
}
}
}

stage('build and push') {
when {
expression {
runEntirePipeline
}
}
environment {
DOCKER_IMAGE = "annleefores/kodiko-codepod:${VERSION}"
}
steps{
steps {
container('kaniko') {
sh "/kaniko/executor --context ${env.WORKSPACE}/server/codepod --destination ${env.DOCKER_IMAGE}"
}
}
}
}
}
}

0 comments on commit bb25502

Please sign in to comment.