Interacting with SDKMan in Jenkins Pipelines

Created by Tass Skoudros, Modified on Tue, 22 Nov, 2022 at 6:27 PM by Tass Skoudros

SDKMan is available on all our agents for our developers to update and manage the versions of all their Java dependencies. The following tools can be installed on demand on any of our agents. 

activemq,ant,asciidoctorj,ballerina,bpipe,btrace,concurnas,connor,cuba,cxf,doctoolchain,flink,gaiden,gradle,gradleprofiler,grails,groovy,groovyserv,hadoop,http4k,infrastructor,java,jbake,jbang,jmc,jmeter,joern,jreleaser,karaf,kcctl,ki,kobweb,kotlin,kscript,layrry,leiningen,maven,mcs,micronaut,mulefd,mvnd,mybatis,neo4jmigrations,pierrot,pomchecker,quarkus,sbt,scala,scalacli,schemacrawler,spark,springboot,sshoogr,taxi,test,tomcat,toolkit,vertx,visualvm,webtau,znai


The interface for managing versions is reasonably simple to do the following. 


sdk list <packagename>
sdk install <packagename>
sdk install gradle 7.5

To use SDKMan in your pipelines, do the following. Add the SDKMAN shim to the top of the pipeline. The shim is only required if you want to interact with the SDKMan script.

set +x
[[ -s "$HOME/.bash_profile" ]] && source "$HOME/.bash_profile"
set -x


Globals = [:]
pipeline {
    agent {
        label 'android-agent'
    }
    options{
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr: '5'))
    }
    stages {
        stage('LoadSDKMAN') {
            steps {
                sh '''
                set +x
                [[ -s "$HOME/.bash_profile" ]] && source "$HOME/.bash_profile"
                set -x
                sdk install gradle
                sdk install java
                '''
            }
        }
        stage('Versions'){
            steps {
                sh '''
                gradle -version
                java -version
                '''
            }
        }
    }
}


Check out the SDKman documentation here.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article