I just start using IntelliJ, mine SharedLibrary is getting bigger and bigger so I wanted move to IDE. I get *.gdsl for autocompletion etc (basic stuff work :) )
But, when my script use @Library notation I get errors (cannot resolve symbol etc), I'm 'kid' in java world (.net daily), I think I missing some Jenkins dependency but which?
build.gradle
repositories {
maven { url 'http://repo.jenkins-ci.org/releases/'}
maven { url 'http://updates.jenkins-ci.org/download/plugins/'}
maven { url 'http://jenkins-updates.cloudbees.com/download/plugins/'}
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.jenkins-ci.main:jenkins-core:2.97'
compile 'org.jenkins-ci.plugins:pipeline-input-step:2.5'
compile 'org.jenkins-ci.plugins.workflow:workflow-cps:2.1'
compile 'org.jenkins-ci.plugins:credentials-binding:1.10'
compile fileTree(dir: 'lib', include: ['*.jar'])
}
This project will only work with SharedLibrary, nothing else :) any tips?
What is a Shared Library in Jenkins? A shared library is a collection of independent Groovy scripts which you pull into your Jenkinsfile at runtime. The best part is, the Library can be stored, like everything else, in a Git repository. This means you can version, tag, and do all the cool stuff you're used to with Git.
Setting up IntelliJ IDEAOpen IntelliJ IDEA. Click on Import Project, and in the popup, choose the directory where Jenkins had been cloned. Select 'Create project from existing sources', and click on Next. Click on Finish.
Oftentimes it is useful to share parts of Pipelines between various projects to reduce redundancies and keep code "DRY". Pipeline has support for creating "Shared Libraries" which can be defined in external source control repositories and loaded into existing Pipelines.
Add a canonical import of the annotation class Library to Jenkinsfile (located in workflow-cps-global-lib.jar)
import org.jenkinsci.plugins.workflow.libs.Library
than use @Library annotation without compilation error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With