jenkins-job-builder user converting to dsl (maybe pipeline)

665 views
Skip to first unread message

dpreilan

unread,
Apr 11, 2017, 8:18:22 AM4/11/17
to Jenkins Users
Have a lot of jobs created with jenkins-jobs-builder that it is proving difficult to maintain.

Looking to move to dsl and possibly pipeline-dsl.

Most of jobs have the following logic: 
 - ability to build debug and/or release builds
 - manually invoked or scm triggered
 - ability to select whether to promote or not, which I use to store artifacts to package repository or a ssh-server depending on job
        - users want build artifacts for each build
        - users may not want those artifacts to be used by dependent jobs OR promoted to package repository.

 For every job, there are 2 sub-jobs to handle the release and debug builds
        - actual builds are performed in a docker container
        - there is a shared id (patch number) between the release and debug builds, but again user can disable one or both via build parameter.
 
I can't quite figure out how to do everything in dsl yet and pipeline-dsl even less.

First, thing. I have a set of parameters for each job, 1 that is using PersistentParameter plugin. This is needed for manually triggered usage where user can set a value and it is remembered the next time. Looking at the dsl-plugin api viewer, I can see the plugin, but can not make it work.

import com.gem.persistentparameter.*

job('ci') {
    description 'Build and test the app.'
    parameters {
        stringParam('p1','master','my des')
        persistentStringParameterDefinition('p2','t123',false, 'help')
    }
    scm {
        github 'sheehan/job-dsl-playground'
    }
    steps {
        gradle 'test'
    }
    publishers {
        archiveJunit 'build/test-results/**/*.xml'
    }
}

javaposse.jobdsl.dsl.DslScriptException: (script, line 7) No signature of method: javaposse.jobdsl.dsl.helpers.BuildParametersContext.persistentStringParameterDefinition() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.Boolean, java.lang.String) values: [p2, t123, false, help]

How can I achieve this? 
However, I can port my yaml/logic to dsl and clean things up and hopefully simplified, and I can use gradle to load jobs into jenkins.
For pipeline-dsl, I am less sure. Loading Jenkinsfile from scm doesn't fit my situation, but possibly a dsl seedjob to handle it can work. The pipeline-dsl has less features so I will probably be face with similar issues as above. How would I handle? To really clean my jobs up, ideally, would want my parameters moved up to pipeline parameters.

Thanks in advance,
Doug

Victor Martinez

unread,
Apr 11, 2017, 12:54:45 PM4/11/17
to Jenkins Users
Hi Doug,

persistentStringParameterDefinition cannot be declared with the import since it is loaded on the fly as long as that plugin has been installed in that jenkins instance.

You can access, mostly all, those plugins and their DSL syntax as explained in the below page:

https://github.com/jenkinsci/job-dsl-plugin/wiki/Automatically-Generated-DSL


Cheers

dpreilan

unread,
Apr 11, 2017, 7:39:29 PM4/11/17
to Jenkins Users
Victor, thanks for reply.

I don't know how to read that link to determine plug in support. Is it accessing the API viewer on my server? If yes, I see the persistent parameter plugin listed

If there is no way to make it work, is there a way to read from a file to get value and alter the default value of a parameter.

Thanks
Doug

Reply all
Reply to author
Forward
0 new messages