Builders

Builders define actions that the Jenkins job should execute. Examples include shell scripts or maven targets. The builders attribute in the Job definition accepts a list of builders to invoke. They may be components defined below, locally defined macros (using the top level definition of builder:, or locally defined components found via the jenkins_jobs.builders entry point.

Component: builders
Macro:builder
Entry Point:jenkins_jobs.builders

Example:

job:
  name: test_job

  builders:
    - shell: "make test"
ant

Execute an ant target. Requires the Jenkins Ant Plugin.

To setup this builder you can either reference the list of targets or use named parameters. Below is a description of both forms:

1) Listing targets:

After the ant directive, simply pass as argument a space separated list of targets to build.

Parameter:space separated list of Ant targets
Parameters:ant-name (str) – the name of the ant installation, defaults to ‘default’ (optional)

Example to call two Ant targets:

builders:
  - ant: "target1 target2"
     ant-name: "Standard Ant"

The build file would be whatever the Jenkins Ant Plugin is set to use per default (i.e build.xml in the workspace root).

2) Using named parameters:

Parameters:
  • targets (str) – the space separated list of ANT targets.
  • buildfile (str) – the path to the ANT build file.
  • properties (list) – Passed to ant script using -Dkey=value (optional)
  • ant-name (str) – the name of the ant installation, defaults to ‘default’ (optional)
  • java-opts (str) – java options for ant, can have multiples, must be in quotes (optional)

Example specifying the build file too and several targets:

builders:
  - ant:
     targets: "debug test install"
     buildfile: "build.xml"
     properties:
        builddir: "/tmp/"
        failonerror: true
     java-opts:
        - "-ea"
        - "-Xmx512m"
     ant-name: "Standard Ant"
artifact-resolver

Allows one to resolve artifacts from a maven repository like nexus (without having maven installed) Requires the Jenkins Repository Connector Plugin

Parameters:
  • fail-on-error (bool) – Whether to fail the build on error (default false)
  • repository-logging (bool) – Enable repository logging (default false)
  • target-directory (str) – Where to resolve artifacts to
  • artifacts (list) –

    list of artifacts to resolve

    Artifact:
    • group-id (str) – Group ID of the artifact
    • artifact-id (str) – Artifact ID of the artifact
    • version (str) – Version of the artifact
    • classifier (str) – Classifier of the artifact (default ‘’)
    • extension (str) – Extension of the artifact (default ‘jar’)
    • target-file-name (str) – What to name the artifact (default ‘’)

Example:

builders:
  - artifact-resolver:
      fail-on-error: true
      repository-logging: true
      target-directory: foo
      artifacts:
        - group-id: commons-logging
          artifact-id: commons-logging
          version: 1.1
          classifier: src
          extension: jar
          target-file-name: comm-log.jar
        - group-id: commons-lang
          artifact-id: commons-lang
          version: 1.2
batch

Execute a batch command.

Parameter:the batch command to execute

Example:

builders:
  - batch: "foo/foo.bat"
builders-from

Use builders from another project. Requires the Jenkins Template Project Plugin.

Parameters:projectName (str) – the name of the other project

Example:

builders:
  - builders-from:
      - project: "base-build"
conditional-step

Conditionaly execute some build steps. Requires the Jenkins Conditional BuildStep Plugin.

Depending on the number of declared steps, a Conditional step (single) or a Conditional steps (multiple) is created in Jenkins.

Parameters:
  • condition-kind (str) – Condition kind that must be verified before the steps are executed. Valid values and their additional attributes are described in the conditions table.
  • on-evaluation-failure (str) – What should be the outcome of the build if the evaluation of the condition fails. Possible values are fail, mark-unstable, run-and-mark-unstable, run and dont-run. Default is fail.
  • steps (list) – List of steps to run if the condition is verified. Items in the list can be any builder known by Jenkins Job Builder.
Condition kind Description
always Condition is always verified
never Condition is never verified
boolean-expression

Run the step if the expression expends to a representation of true

condition-expression:
 Expression to expand
current-status

Run the build step if the current build status is within the configured range

condition-worst:
 Worst status
condition-best:Best status
shell

Run the step if the shell command succeed

condition-command:
 Shell command to execute
windows-shell

Similar to shell, except that commands will be executed by cmd, under Windows

condition-command:
 Command to execute
file-exists

Run the step if a file exists

condition-filename:
 Check existence of this file
condition-basedir:
 If condition-filename is relative, it will be considered relative to either workspace, artifact-directory, or jenkins-home. Default is workspace.

Example:

builders:
  - conditional-step:
      condition-kind: boolean-expression
      condition-expression: "${ENV,var=IS_STABLE_BRANCH}"
      on-evaluation-failure: mark-unstable
      steps:
          - shell: "echo Making extra checks"
copyartifact

Copy artifact from another project. Requires the Jenkins Copy Artifact plugin.

Parameters:
  • project (str) – Project to copy from
  • filter (str) – what files to copy
  • target (str) – Target base directory for copy, blank means use workspace
  • flatten (bool) – Flatten directories (default: false)
  • which-build (str) – which build to get artifacts from (optional, default last-successful)
  • build-number (str) – specifies the build number to get when when specific-build is specified as which-build
  • permalink (str) – specifies the permalink to get when permalink is specified as which-build
  • stable (bool) – specifies to get only last stable build when last-successful is specified as which-build
  • fallback-to-last-successful (bool) – specifies to fallback to last successful build when upstream-build is specified as which-build
  • param (string) – specifies to use a build parameter to get the build when build-param is specified as which-build
Which-build values:
 
  • last-successful
  • specific-build
  • last-saved
  • upstream-build
  • permalink
  • workspace-latest
  • build-param
Permalink values:
 
  • last
  • last-stable
  • last-successful
  • last-failed
  • last-unstable
  • last-unsuccessful

Example:

builders:
  - copyartifact:
      project: foo
      filter: *.tar.gz
      target: /home/foo
      which-build: specific-build
      build-number: 123
      flatten: true
gradle

Execute gradle tasks. Requires the Jenkins Gradle Plugin.

Parameters:
  • tasks (str) – List of tasks to execute
  • gradle-name (str) – Use a custom gradle name (optional)
  • wrapper (bool) – use gradle wrapper (default false)
  • executable (bool) – make gradlew executable (default false)
  • switches (list) – Switches for gradle, can have multiples

Example:

builders:
  - gradle:
      gradle-name: "gradle-1.2"
      wrapper: true
      executable: true
      switches:
        - "-g /foo/bar/.gradle"
        - "-PmavenUserName=foobar"
      tasks: |
             init
             build
             tests
grails

Execute a grails build step. Requires the Jenkins Grails Plugin.

Parameters:
  • use-wrapper (bool) – Use a grails wrapper (default false)
  • name (str) – Select a grails installation to use (optional)
  • force-upgrade (bool) – Run ‘grails upgrade –non-interactive’ first (default false)
  • non-interactive (bool) – append –non-interactive to all build targets (default false)
  • targets (str) – Specify target(s) to run separated by spaces
  • server-port (str) – Specify a value for the server.port system property (optional)
  • work-dir (str) – Specify a value for the grails.work.dir system property (optional)
  • project-dir (str) – Specify a value for the grails.project.work.dir system property (optional)
  • base-dir (str) – Specify a path to the root of the Grails project (optional)
  • properties (str) – Additional system properties to set (optional)
  • plain-output (bool) – append –plain-output to all build targets (default false)
  • stack-trace (bool) – append –stack-trace to all build targets (default false)
  • verbose (bool) – append –verbose to all build targets (default false)
  • refresh-dependencies (bool) – append –refresh-dependencies to all build targets (default false)

Example:

builders:
  - grails:
      use-wrapper: "true"
      name: "grails-2.2.2"
      force-upgrade: "true"
      non-interactive: "true"
      targets: "war ear"
      server-port: "8003"
      work-dir: "./grails-work"
      project-dir: "./project-work"
      base-dir: "./grails/project"
      properties: "program.name=foo"
      plain-output: "true"
      stack-trace: "true"
      verbose: "true"
      refresh-dependencies: "true"
inject

Inject an environment for the job. Requires the Jenkins EnvInject Plugin.

Parameters:
  • properties-file (str) – the name of the property file (optional)
  • properties-content (str) – the properties content (optional)

Example:

builders:
  - inject:
      properties-file: example.prop
      properties-content: EXAMPLE=foo-bar
maven-target

Execute top-level Maven targets

Parameters:
  • goals (str) – Goals to execute
  • properties (str) – Properties for maven, can have multiples
  • pom (str) – Location of pom.xml (defaults to pom.xml)
  • maven-version (str) – Installation of maven which should be used (optional)

Example:

builders:
  - maven-target:
      maven-version: Maven3
      pom: parent/pom.xml
      goals: clean
      properties:
        - foo=bar
        - bar=foo
msbuild

Build .NET project using msbuild. Requires the Jenkins MSBuild Plugin.

Parameters:
  • msbuild-version (str) – which msbuild configured in Jenkins to use (optional)
  • solution-file (str) – location of the solution file to build
  • extra-parameters (str) – extra parameters to pass to msbuild (optional)
  • pass-build-variables (bool) – should build variables be passed to msbuild (defaults to true)
  • continue-on-build-failure (bool) – should the build continue if msbuild returns an error (defaults to false)

Example:

builders:
  - msbuild:
      solution-file: "MySolution.sln"
      msbuild-version: "msbuild-4.0"
      extra-parameters: "/maxcpucount:4"
      pass-build-variables: False
      continue-on-build-failure: True
multijob

Define a multijob phase. Requires the Jenkins Multijob Plugin.

This builder may only be used in jenkins_jobs.modules.project_multijob.MultiJob projects.

Parameters:
  • name (str) – MultiJob phase name
  • condition (str) – when to trigger the other job (default ‘SUCCESSFUL’)
  • projects (list) –

    list of projects to include in the MultiJob phase

    Project:
    • name (str) – Project name
    • current-parameters (bool) – Pass current build parameters to the other job (default false)
    • git-revision (bool) – Pass current git-revision to the other job (default false)
    • property-file (str) – Pass properties from file to the other job (optional)
    • predefined-parameters (str) – Pass predefined parameters to the other job (optional)

Example:

builders:
  - multijob:
      name: PhaseOne
      condition: SUCCESSFUL
      projects:
        - name: PhaseOneJobA
          current-parameters: true
          git-revision: true
        - name: PhaseOneJobB
          current-parameters: true
          property-file: build.props
  - multijob:
      name: PhaseTwo
      condition: UNSTABLE
      projects:
        - name: PhaseTwoJobA
          current-parameters: true
          predefined-parameters: foo=bar
        - name: PhaseTwoJobB
          current-parameters: false
shell

Execute a shell command.

Parameter:the shell command to execute

Example:

builders:
  - shell: "make test"
trigger-builds

Trigger builds of other jobs. Requires the Jenkins Parameterized Trigger Plugin.

Parameters:
  • project (str) – the Jenkins project to trigger
  • predefined-parameters (str) – key/value pairs to be passed to the job (optional)
  • current-parameters (bool) – Whether to include the parameters passed to the current build to the triggered job.
  • svn-revision (bool) – Whether to pass the svn revision to the triggered job
  • block (bool) – whether to wait for the triggered jobs to finish or not (default false)

Example:

builders:
  - trigger-builds:
      - project: "build_started"
        predefined-parameters:
          FOO="bar"
        block: true

Previous topic

General Job Configuration

Next topic

Hipchat

This Page