Skip to content

Commit

Permalink
Update Jenkins pipeline to use containers as build agents
Browse files Browse the repository at this point in the history
Jenkinsfile is pulled in by the SMQE jenkins and is responsible for running gradle build tasks, and
uploading to sonarqube.
  • Loading branch information
lindseyburnett committed Jul 27, 2022
1 parent 6a9ada1 commit 69c7bf9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 67 deletions.
120 changes: 54 additions & 66 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,63 @@
pipeline {
options { buildDiscarder(logRotator(numToKeepStr: '50')) }
agent {
label 'rhsm'
}
stages {
stage('Clean') {
steps {
sh "./podman_run.sh ./gradlew --no-daemon clean"
}
}
stage('Build') {
steps {
sh "./podman_run.sh ./gradlew --no-daemon assemble"
}
}
stage('Unit tests') {
steps {
sh "./podman_run.sh ./gradlew --no-daemon test"
}
}
stage('Spotless') {
steps {
sh "./podman_run.sh ./gradlew --no-daemon spotlessCheck"
}
}
stage('Upload PR to SonarQube') {
when {
changeRequest()
}
steps {
withSonarQubeEnv('sonarcloud.io') {
sh "./podman_run.sh ./gradlew --no-daemon sonarqube -Duser.home=/tmp -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.pullrequest.key=${CHANGE_ID} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.branch=${BRANCH_NAME} -Dsonar.organization=rhsm -Dsonar.projectKey=rhsm-subscriptions"
}
}
}
stage('Upload Branch to SonarQube') {
when {
not {
changeRequest()
}
}
steps {
withSonarQubeEnv('sonarcloud.io') {
sh "./podman_run.sh ./gradlew --no-daemon sonarqube -Duser.home=/tmp -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.organization=rhsm -Dsonar.projectKey=rhsm-subscriptions"
}
}
}
stage('SonarQube Quality Gate') {
steps {
withSonarQubeEnv('sonarcloud.io') {
echo "SonarQube scan results will be visible at: ${SONAR_HOST_URL}/dashboard?id=rhsm-subscriptions"
}
retry(4) {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
// "rethrow" as something retry will actually retry, see https://issues.jenkins-ci.org/browse/JENKINS-51454
if (e.causes.find { it instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution$ExceededTimeout } != null) {
error("Timeout waiting for SonarQube results")
}
}
}
}
kubernetes {
label 'swatch'
// all your pods will be named with this prefix, followed by a unique id
idleMinutes 5 // how long the pod will live after no jobs have run on it
containerTemplate {
name 'openjdk11'
image 'registry.access.redhat.com/ubi8/openjdk-11'
command 'sleep'
args '99d'
resourceRequestCpu '2'
resourceLimitCpu '2'
resourceRequestMemory '4Gi'
resourceLimitMemory '6Gi'
}

defaultContainer 'openjdk11'
// define a default container if more than a few stages use it, will default to jnlp container
}
}
stages {
stage('Build') {
steps {
sh "./gradlew build"
}
}

stage('Upload PR to SonarQube') {
when {
changeRequest()
}
steps {
withSonarQubeEnv('sonarcloud.io') {
sh "./gradlew sonarqube -Duser.home=/tmp -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.pullrequest.key=${CHANGE_ID} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.branch=${BRANCH_NAME} -Dsonar.organization=rhsm -Dsonar.projectKey=rhsm-subscriptions"
}
}
}
stage('SonarQube Quality Gate') {
steps {
withSonarQubeEnv('sonarcloud.io') {
echo "SonarQube scan results will be visible at: ${SONAR_HOST_URL}/dashboard?id=rhsm-subscriptions"
}
retry(4) {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
// "rethrow" as something retry will actually retry, see https://issues.jenkins-ci.org/browse/JENKINS-51454
if (e.causes.find { it instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution$ExceededTimeout } != null) {
error("Timeout waiting for SonarQube results")
}
}
}
}
}
}
}
post {
always {
junit '**/build/test-results/test/*.xml'
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nebula.release.features.replaceDevWithImmutableSnapshot=true
org.gradle.jvmargs=-Xmx2048m "-XX:MaxMetaspaceSize=256m"
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.jvmargs=-Xmx2048m "-XX:MaxMetaspaceSize=1024m"

0 comments on commit 69c7bf9

Please sign in to comment.