Skip to main content

Groovy syntax to retrieve a job's type

Answered

Comments

6 comments

  • Manuel Cardenas

    Hi Brandon,

     

    You can run this script from the Jenkins script console. This is a very basic approach, but I am sure that you can refine it.

    ```

    Jenkins.instance.getAllItems(Job).each{job -> job.isBuildable()

    if (job.isBuildable()!=null)

    println job.name +"--->"+ job.class
    }

    ```

     

    Best regards,

    1
  • Brandon Bhagwandeen

    Thanks @Manuel, that works amazingly.

     

    Now i'm trying to filter out certain classes so i can find out all the classes that exist in my results. For some reason my statement:

    if(!(job instanceof MavenModule))

    still does not filter out  class 'hudson.maven.MavenModule' results

    0
  • Brandon Bhagwandeen

    I think it's because MavenModule is not a job, but a plugin?

    0
  • Manuel Cardenas

    You will need to provide the FQN: hudson.maven.MavenModuleSet 

    That should work. If you review the output from the execution of the first script that would help you use the correct class name for the jobs that you want to work with.

     

    Hope that helps.

     

    1
  • Brandon Bhagwandeen

    Thank you @Manuel. That works.

    0
  • Brandon Bhagwandeen

    In case this question gets searched for again,

    job.getClass().simpleName

    This would show only the project class type name without the library information.

    For example, you would see this if anyone would need to: 

    test--->FreeStyleProject
    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.