by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Gregory Paciga
    @gpaciga
    regardling library configs, if I have an optional config, does it make sense to set it to a default value if it's not provided within the @Init or maybe an @validate?
    @Init
    void call(Map args = [:], Closure body) {
        config.myparam = config.myparam ?: 'defaultValue'
    }
    steven-terrana
    @steven-terrana
    i don’t think updates to the config variable will persist so you’d have to do it in each step. It would be an interesting idea to be able to declare the default value for optional steps inside your library configuration file
    Gregory Paciga
    @gpaciga
    they do seem to persist, but sounds like that might be a happy accident rather than purposeful
    i just the usual pattern is to just check if it's defined in the steps that need it?
    steven-terrana
    @steven-terrana

    hahah i feel like that’s a happy accident that i should probably break tbh..

    bc imagine library A contributes a step A and library B contributes a step B..

    in A i could do: B.config = [:] and break another library’s step

    it assumes malicious intent bc you’d have to go pretty out of your way to hit that situation
    but i don’t think it should be possible

    i do think it would make sense for library configs to declare default values.

    or for you to only be able to manipulate that config variable within the same library

    steven-terrana
    @steven-terrana
    Thoughts? i’m open to ideas here on how you all think it should work
    Vincent Letarouilly
    @Opa-

    I was setting the default values with @Init like @gpaciga mentioned and I was thinking it was intended to work this way :D

    I think it'd be better to define the defaults into the library config, that way you define everything in the same file

    Gregory Paciga
    @gpaciga
    defaults in the config make sense to me too. breaking/fixing ability to set config values is fine as long as there's an alternative. though I wonder too about calculated/derived values, like if on init you take a config that's a simple user-friendly value and use that to generate a config value to be used internally in multiple steps. I don't really know the right terminology for it, but more generally, do libraries have a namespace where I can set values, like class members/fields?
    makashu
    @makashu
    Hi, is it possible to load libraries from specific branch in addition to master which is supported by pipeline libraries?
    My use case is something like library "jte-libraries@feature/test-branch" in jenkinsfile or pipeline_config.groovy, is that supported?
    steven-terrana
    @steven-terrana
    @makashu that is not currently possible
    3 replies
    Vearak Thach
    @vthach24
    Hello all, I'm attempting to use JTE and write a pipeline for SonarQube. Can anyone assist in getting me started? Some good documents or examples?
    Daniel Fullarton
    @linead
    @vthach24 I started here - https://boozallen.github.io/sdp-docs/overview/1/index.html once you get used to the model it's pretty straight forward
    steven-terrana
    @steven-terrana

    thanks @linead!

    @vthach24 I usually recommend these Learning Labs when first getting started with JTE

    Once you get through that, you can take a look at Booz Allen’s existing SonarQube library for a starting point if you’re interested.
    Docs: https://boozallen.github.io/sdp-docs/sdp-libraries/2.2/libraries/sonarqube.html
    Library: https://github.com/boozallen/sdp-libraries/tree/master/libraries/sonarqube

    mfuxi
    @mfuxi
    I would really love to get a full example of how to run a simple maven pipeline with custom node since I still can't make it work
    The only method I had managed to run a simple maven pipeline was only on the Jenkins master
    If i'm trying to run on a node i'm getting this error:
    step node from the library node does not have the method call(CpsClosure2)
    my node.groovylooks like that:
    void call(String label= null){
       steps.node( label ?: config.label ?: ""){
           println "test 123"
       }
    }
    my pipeline_config.groovy:
    libraries{
        node {
             label = "jte"
        }
        maven
    }
    mfuxi
    @mfuxi

    Weird, I updated my node.groovy to look like that:

    void call(String label = null, Closure body){
       steps.node( label ?: config.label ?: “” ){
        body()
      }
    }

    And now it works, and runs the build on the node I supported within the pipeline_config.groovy but I don't understand why, can you explain @steven-terrana ?

    Also, my Jenkinsfile looks like that:

    build()

    Why don't I need to call to node() as well?

    steven-terrana
    @steven-terrana

    when you say node(“something”){ // some code }

    that’s the same thing as saying node(“something”, { // some code })

    so the { } is called a Closure and it’s the last input parameter to the node step.

    so when your step was just call(String label = null) it was never accepting the closure parameter.

    you are calling the node step. In your maven library, i’m assuming you have a node{ // some code } block in there somewhere?

    that node block is actually invoking your node library’s node step.

    Gregory Paciga
    @gpaciga
    are there examples of configuring a JTE job with JobDSL? I saw an issue in the old repo discussing it, but can't find anything in the docs
    Gregory Paciga
    @gpaciga
    ah nevermind, found it under factory { templateBranchProjectFactory { ... } }
    Miguel Quintero
    @miqui
    hi, newbie question: how do i configure a specific build agent? (similar to what is done in the traditional Jenkinsfile)
    steven-terrana
    @steven-terrana

    hey @miqui - JTE uses the scripted pipeline syntax. so configuring a build agent would be done the same was as Scripted pipelines.

    if you’re looking to configure a single build agent across the entire pipeline run then you could wrap the whole template in a node block:

    node(“someNodeLabel”){
      step1()
      step2()
    }
    Miguel Quintero
    @miqui
    ok, cool.. thanks @steven-terrana , thanks for your time, i also see what looked like another example using node in the library block... thanks
    Vincent Brouillet
    @Vince-Cercury
    How do I check if a lib or step exists?
    I want to call that step if it exists or do something else if it does not. Is there a more graceful way than try/catch around the call
    steven-terrana
    @steven-terrana
    @Vince-Cercury
    if( getBinding().hasStep(“stepName”) ){
      stepName()
    } else {
      // do something else
    }
    Vincent Brouillet
    @Vince-Cercury
    Thanks
    Vincent Brouillet
    @Vince-Cercury
    Upgrading from 1.5 to 1.7.1. My job dsl is broken, the config template part. Looking at job XML config after upgrading plugin and setting up the config again I don't see any difference. Any tip or example?
    Vincent Brouillet
    @Vince-Cercury
    Found how to do it. I'll raise a doc PR
    Chris Bolton
    @Gl4di4torRr

    application_environment is null when passing into call function

    What is the problem?

    [Pipeline] End of Pipeline hudson.remoting.ProxyException: java.lang.NullPointerException: 
    Cannot get property 'release' on null object at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)

    We know that the app_env is NOT being passed into our deploy_to call method but we are unable (so far) to determine where the object is not being assigned.

    What have we tried?

    Here is our parent config:

    allow_scm_jenkinsfile = false
    
    application_environments{
        dev{
            long_name = "Development"
        }
    }
    
    libraries{
        merge=true
    }
    
    template_methods{
    deploy_to dev
    }

    Here is our parent Jenkinsfile:

    deploy_to()

    Here is our deploy_to.groovy:

    void call(def app_env){
        String release = app_env.release // Null Pointer occurs here b/c app_env is null
    }

    Here is the app (latest) config:

    application_environments{
        dev{
                release = "myapp"
            }
    }
    
    libraries{
        openshift
    }
    steven-terrana
    @steven-terrana

    hey @Gl4di4torRr!

    in your parent config, change:

    template_methods{
      deploy_to dev
    }

    To

    template_methods{
      deploy_to
    }

    and then in your parent Jenkinsfile update it to:

    deploy_to dev

    and you should be golden

    2 replies

    some more explanation:

    the template_methods block exists to tell JTE what steps you expect to invoke from the pipeline template (parent Jenkinsfile) in the event that after loading hte libraries and creating any default step implementations one of those methods has not been implemented to go create a no-op step to avoid “method not defined” errors.

    then - the Jenkinsfile (pipeline template) is where you’d actually use the step - and pass the input argument

    Jackie Weng
    @jemerald
    Is there any documentation on setup JTE pipeline config at the folder level with Job DSL?

    I figured out how to setup the JTE on multibranch pipeline based on an old declined PR

    multibranchPipelineJob(path) {
        configure {
            it / factory(class: 'org.boozallen.plugins.jte.job.TemplateBranchProjectFactory') {
                filterBranches(true)
            }
        }
    }

    But the folder setup code in that PR seems to be specific to Github Org folder :(

    steven-terrana
    @steven-terrana

    hey @jemerald.

    If you checkout the job-dsl api-viewer on your Jenkins instance (<JENKINS_URL>/plugin/job-dsl/api-viewer/index.html#path/folder) it shows the DSL syntax.

    for example..

    folder("my-test-folder"){
      properties{
        templateConfigFolderProperty{
          tier{
            configurationProvider{
              scmPipelineConfigurationProvider{
                baseDir("something")
                scm{
                  gitSCM{ ... } 
                }
              }
            }
          }
        }
      }
    }
    jzr1991
    @jzr1991
    Hi @steven-terrana, great work (and support on this channel too). A question that I think relates a little to one above - is there a nice convention for allowing teams to insert a step in to the pipeline?
    By that I mean, let's say I have a simple pipeline template that mandates a build, test, and deploy. But then a team comes along and wants to use it, but also go above and beyond by adding in a static_code_analysis after test, to improve upon the basic mandatory steps I've defined. Without having a variation of the pipeline in pipeline_templates, is there a way? We might have lots of teams wanting to add lots of extra steps and I'm wary of getting to a place where we have 50 pipeline variations to suit all these cases. Thanks!
    steven-terrana
    @steven-terrana

    hmmm.

    the closest thing to that right now would be the Default Step Implementation which lets users dynamically “create” a step from their pipeline configuration file.

    it’s pretty limited to what it can do though.. you just provide a container image and a script path / command and it uses the Docker Pipeline Plugin to execute the command in teh container image specified.

    but that’s how i try to get around creating libraries for random things.

    one thing you could maybe do is rely exclusively on the lifecycle hook stuff?

    basically let teams configure a library source (scoped probably to just them) and then they can build their own steps.

    so if they wanted to run some custom stuff before the template they could create an @Init step?
    or for after the pipeline they could create an @CleanUp or @Notify step?

    if they wanted to inject functionality before/after a step in the template they could use the @BeforeStep and @AfterStep functionality?

    this isn’t an ideal solution but i can’t think of a cleaner way right now

    do you have any suggestions for the syntax of how something like that might work?

    the risk with that second approach would be that users could then override the steps in the template they’re inheriting. but maybe that’s okay for your use case?
    Vincent Brouillet
    @Vince-Cercury
    Hi. I'm a little confuse on how to create a simple pipeline with JTE. Not a multi branch one. I'm running JTE 1.7.1
    It looks like I can specify in line config and template. But not from scm. And where do I supply lib?
    Jackie Weng
    @jemerald
    Thanks @steven-terrana I didn't know about the DSL api-viewer, that helped a lot.

    I'm currently trying to configure the multibranch pipeline to auto build branches, PRs, and tags.
    While branches and PRs builds fine, the tags doesn't seems to trigger auto-build. Here' the multibranch pipeline log:

    Checking tag test-tag2 from <my-repo>
    ‘pipeline_config.groovy’ found
    Met criteria
    Changes detected: test-tag2 (null → 98aa7a282ac0b30a4a3015be52de0867edc47aa5)
    No automatic build triggered for test-tag2

    Jackie Weng
    @jemerald
    ah, nevermind, it's not JTE related
    steven-terrana
    @steven-terrana
    @Vince-Cercury - currently you can’t specify libraries at the indiviudal Pipeline Job level. you would need to either add the libs globally in Manage Jenkins > Configure System > Jenkins Templating Engine or create a Folder for the pipeline job to be in and then add the libs to this new Folder.