simple build (DSL) for pipeline plugin

357 views
Skip to first unread message

Michael Neale

unread,
Feb 24, 2016, 9:42:41 PM2/24/16
to Jenkins Users
Hey I thought some may be interested in this Pipeline DSL enhancement (ie a plugin that enhances Jenkins pipeline) which is installable as a plugin: https://wiki.jenkins-ci.org/display/JENKINS/Simple+Build+For+Pipeline+Plugin - interested in thoughts/feedback (you use it where you would use a Jenkinsfile or pipeline script). 


Martin d'Anjou

unread,
Mar 11, 2016, 2:56:51 PM3/11/16
to Jenkins Users
Hi Michael,

I played with the plugin quite a bit. I am very enthusiastic about this plugin, because it gives me a way to manage the pipeline script development as if it were a regular plugin (code, test, version and release), while being much easier to write than a regular plugin.

I do not plan to use the mini simpleBuild DSL as is, but I plan to use its base class PipelineDSLGlobal and build a different core with it. I do not plan on using the Jenkinsfile aspect yet, because I have multiple CD/CI pipelines per branch in my projects, and only one Jenkinsfile is supported currently.

One thing I was trying to do was to acess the "env" and the build parameters from inside the simpleBuild Closure. I changed "env" to "map" in the source (so "env" would not be hidden), and I attempted the following:
simpleBuild {
   
...
    map
= [url: "http://host/path/${PARAM}/${env.BUILD_NUMBER}"]
   
...
}

I tried various ways of setting the closure delegate (see it on my github fork) but the alternative I tried results in not being able to resolve the "scm" in "checkout scm". If I use ${this.env.BUILD_NUMBER}, then it works, but I would feel more comfortable using your code if I understood why ${env.BUILD_NUMBER} cannot be resolved. The Closure owner is a WorkflowScript after all, and it should have "env".

Thanks,
Martin

Michael Neale

unread,
Mar 13, 2016, 7:22:16 PM3/13/16
to Jenkins Users
Hi Martin. 

Yes that is quite confusing. Well for one, I used the "env" to mean the key in a closure that ends up in config, which is slightly naughty, given there is already an env global - so probably shouldn't do what I did ;) 

I am not sure why it wouldn't work like that - if you use double quotes, then I think it would use string interpolation to expand it (perhaps there is a missing call to the token expander). 

checkout scm - that is for when it is multibranch - that will only work if you are running the job form a Jenkinsfile

Martin d'Anjou

unread,
Mar 30, 2016, 11:44:33 AM3/30/16
to Jenkins Users
Hi Michael,

I am still pretty happy about the simpleBuild method of writing Pipeline Plugins. It is very easy to extend from the PipelineDSLGlobal base class. I wrote some more code, and I can test my plugin on the command line (yay!) as well as with mvn hpi:run. But when I try to upload my plugin to a standalone Jenkins installation the upload center gives me this error:

java.io.IOException: Failed to dynamically deploy this plugin
  at hudson
.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:1383)
  at hudson
.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:1161)
  at java
.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
  at java
.util.concurrent.FutureTask.run(FutureTask.java:262)
  at hudson
.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:110)
  at java
.lang.Thread.run(Thread.java:744)
Caused by: java.io.IOException: Failed to install simple-build-extension plugin
  at hudson
.PluginManager.dynamicLoad(PluginManager.java:487)
  at hudson
.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:1379)
 
... 5 more
Caused by: java.io.IOException: Dependency simple-build-for-pipeline (0.2) doesn't exist
  at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:533)
  at hudson.PluginManager.dynamicLoad(PluginManager.java:477)
  ... 6 more

My pom.xml appears to have the relevant bits:

    <repositories>
       
<repository>
           
<id>repo.jenkins-ci.org</id>
           
<url>http://repo.jenkins-ci.org/public/</url>
       
</repository>
   
</repositories>
   
<pluginRepositories>
       
<pluginRepository>
           
<id>repo.jenkins-ci.org</id>
           
<url>http://repo.jenkins-ci.org/public/</url>
       
</pluginRepository>
   
</pluginRepositories>

   
<dependencies>
       
<dependency>
           
<groupId>org.jenkins-ci.plugins</groupId>
           
<artifactId>simple-build-for-pipeline</artifactId>
           
<version>0.2</version>
       
</dependency>
...

Do you know what's missing, why Jenkins can't load a plugin that extends from simple-build-for-pipeline?

Thanks,
Martin

Martin d'Anjou

unread,
Mar 30, 2016, 1:45:27 PM3/30/16
to Jenkins Users
I will reply to my own question: plugins uploaded manually do not fetch their dependencies.

Michael Neale

unread,
Mar 30, 2016, 6:13:36 PM3/30/16
to Jenkins Users
Yes - interestingly that question/answer comes up a lot. Yes, you have to install deps yourself if using Advanced "tab" to install it. 

If you use mvn hpi:run to run it in development you don't need to worry about it (which is why few come across this). 

If this bites you enough, might I suggest opening an issue to see if there is interest in having an option to automatically install deps of an uploaded plugin (that are missing) if it can? 

Martin d'Anjou

unread,
Apr 4, 2016, 9:29:51 AM4/4/16
to Jenkins Users
I have written enough code to occasionally get a serialization error:
Apr 04, 2016 8:22:44 AM org.jenkinsci.plugins.workflow.cps.CpsThreadGroup saveProgram
WARNING
: program state save failed
java
.io.NotSerializableException: org.codehaus.groovy.runtime.HandleMetaClass

Do you know how I can test serialization of the whole "def call(body) { ... }" code and everything it contains (imports, etc.)?

Thanks,
Martin

Michael Neale

unread,
Apr 4, 2016, 6:19:54 PM4/4/16
to Jenkins Users
Good question, no not sure off the top of my head. I know Jesse identified a problem recently with checkpoints (and unrelated feature, but touches on save program I believe). 
Reply all
Reply to author
Forward
0 new messages