Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arehmandev/736daba40a3e1ef1fbe939c6674d7da8 to your computer and use it in GitHub Desktop.
Save arehmandev/736daba40a3e1ef1fbe939c6674d7da8 to your computer and use it in GitHub Desktop.
1. Setup a project
2. Add groovy SDK support:
https://www.bonusbits.com/wiki/HowTo:Add_Groovy_SDK_to_IntelliJ_IDEA
3. Download http://(yourjenkinsurl)/job/(yourpipelinejob)/pipeline-syntax/gdsl
- this will give you the .gdsl file - download this to the src folder of your project.
4. Finally follow this step - right click on the src folder -> Mark directory as -> Sources Root
5. Now create a .groovy file and begin writing, the autocompletion will work.
references:
http://stackoverflow.com/questions/41062514/use-gdsl-file-in-a-java-project-in-intellij
@flitzie
Copy link

flitzie commented May 14, 2020

@ranma2913
Thanks for sharing. I came to the same solution by adding "import org.jenkinsci.plugins.workflow.libs.Library" too.
Using implementation makes sense but only if the repository/project itself contains or is the shared library groovy code (in your case it does).

I am using this notation in Gradle because I noticed that hpi files are still resolved unnecessarily:

implementation('org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.16') {
   // explicitly adding the jar artifact for the IDE and exclude hpi file ...
   artifact {
      name = 'workflow-cps-global-lib'
      type = 'jar'
   }
}

try it out :-)

But when it comes to a consumer project using the shared library code then my suggestion is to separate the sourceSet by defining it for example like this:

configurations {
   ideJenkinsfileSupport
}

Otherwise you "poison" your actual project code with shared library code, which you don't want to have in your productive environment :-)

@salimfadhleyhtp
Copy link

The instructions say to download the gdsl, but where and to which filename?

@smangels
Copy link

smangels commented May 20, 2021

The instructions say to download the gdsl, but where and to which filename?

Download them from a pipeline in Jenkins (link on the left pane), filename doesn't matter. What matters is that IntelliJ recognizes the file as GDSL (thus the "gdsl" file extension. :-)

@Mr-LiuDC
Copy link

Thanks for the ideas here, I have added some other pipeline syntax.

https://gist.github.com/Mr-LiuDC/8a1fbe27e8fbd42361185b06085ef4c3

@karfau
Copy link

karfau commented Feb 3, 2022

What groovy version is used by people that get this working?
I tried 4.0.0-rc2, 3.0.9, 2.5.15 without success.

I only ever get the following:
image

image

@gsusI
Copy link

gsusI commented Jul 30, 2022

For the issue 'pipeline' cannot be applied to '(groovy.lang.Closure)'

Add: method(name: 'pipeline', type: 'Object', params: [body:'Closure'], doc: 'Pipeline root element')

@jaydubb12
Copy link

@karfau I did get it working...see this project I was able to setup - https://github.com/jaydubb12/jenkins-dsl-pipelines

@NicoStrecker
Copy link

@gsusI i had to set the project sdk set to java 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment