All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.goldin.plugins.jenkins.beans.Invoke.groovy Maven / Gradle / Ivy

package com.github.goldin.plugins.jenkins.beans

import static com.github.goldin.plugins.common.GMojoUtils.*


/**
 * Specifies invocation of other jobs: "Trigger parameterized build on other projects" checkbox
 */
@SuppressWarnings( 'StatelessClass' )
class Invoke
{
    String      jobs               // Comma-separated job IDs to invoke
    Set jobsSplit          // Job IDs to invoke (split)
    boolean     always    = false  // Whether other jobs should always be invoked
    boolean     stable    = true   // Whether other jobs should be invoked if build is stable
    boolean     unstable  = false  // Whether other jobs should be invoked if build is unstable (tests failed)
    boolean     failed    = false  // Whether other jobs should be invoked if build has failed

    /**
     * Job parameters
     */

    boolean     triggerWithoutParameters = false  // Trigger build without parameters
    boolean     currentBuildParams       = false  // Current build parameters
    boolean     subversionRevisionParam  = false  // Subversion revision parameters
    boolean     gitCommitParam           = false  // Pass-through Git Commit that was built
    String      params                            // Predefined parameters
    String      propertiesFileParams              // Parameters from properties file


   /**
    * Sets the jobs (job IDs) to invoke.
    * Called by Maven when reading plugin 
    */
    void setJobs( String jobs )
    {
        assert jobs?.trim()?.length()
        this.jobs      = jobs
        this.jobsSplit = ( split( this.jobs ) as Set ).asImmutable()
    }


    /**
     * Gets invocation condition according to "Parameterized Trigger Plugin"
     * http://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
     */
    List getCondition ()
    {
        def condition =
            ( always  || ( stable && unstable && failed )) ?
                [ 'ALWAYS', 'is complete (always trigger)' ] :
            ( stable && unstable ) ?
                [ 'UNSTABLE_OR_BETTER', 'is stable or unstable but not failed' ] :
            ( failed ) ?
                [ 'FAILED',   'has failed'  ] :
            ( unstable ) ?
                [ 'UNSTABLE', 'is unstable' ] :
            ( stable ) ?
                [ 'SUCCESS',  'is stable'   ] :
            null

        assert condition, 'At least one of ,  or  should be set to "true" to enable invocation of [$jobs]'
        condition
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy