Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ and jenkins pipeline shared library project

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?

like image 400
kkkkuba Avatar asked Dec 28 '17 17:12

kkkkuba


People also ask

How does Jenkins shared library work?

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.

How does Jenkins integrate with IntelliJ?

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.

What is pipeline library in Jenkins?

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.


1 Answers

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.

enter image description here

like image 102
Nikolai Avatar answered Sep 27 '22 17:09

Nikolai