All Implemented Interfaces:
Configurable, KeyVal.Mixin, UtilsMixin

public class Job extends HasEnvironmentVariables<Job>
Represents a job.

/*
 * Copyright 2022 Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


  job('build') {
    tasks {
      exec {
        commandLine = ['make', '-j3', 'doc', 'install']
      }
    }
  }

  • Constructor Details

  • Method Details

    • artifacts

      The list of artifacts generated by this job.

      /*
       * Copyright 2022 Thoughtworks, Inc.
       *
       * Licensed under the Apache License, Version 2.0 (the "License");
       * you may not use this file except in compliance with the License.
       * You may obtain a copy of the License at
       *
       *     http://www.apache.org/licenses/LICENSE-2.0
       *
       * Unless required by applicable law or agreed to in writing, software
       * distributed under the License is distributed on an "AS IS" BASIS,
       * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       * See the License for the specific language governing permissions and
       * limitations under the License.
       */


        job('build') {
          artifacts {
            build {
              source = 'target/jcoverage'
              destination = 'Jcoverage'
            }
            test {
              source = 'target/reports/junit/**/*.xml'
              destination = 'junit-xml'
            }
            external {
              id = 'docker-release-candidate'
              storeId = 'dockerhub'
              configuration = [
                image: 'gocd/gocd-server',
                tag  : 'latest'
              ]
              secureConfiguration = [
                DB_PASSWORD: 'AES:yBk975e1rJiuRnAx9AZ6Og==:ee6yi/2sEh5/TUlbmNWelg=='
              ]
            }
          }
        }

    • tasks

      The sequence of tasks executed by this job.

      /*
       * Copyright 2022 Thoughtworks, Inc.
       *
       * Licensed under the Apache License, Version 2.0 (the "License");
       * you may not use this file except in compliance with the License.
       * You may obtain a copy of the License at
       *
       *     http://www.apache.org/licenses/LICENSE-2.0
       *
       * Unless required by applicable law or agreed to in writing, software
       * distributed under the License is distributed on an "AS IS" BASIS,
       * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       * See the License for the specific language governing permissions and
       * limitations under the License.
       */


        job('build') {
          tasks {
            exec {
              commandLine = ['./gradlew', 'clean', 'assemble', 'check']
            }
            bash {
              commandString = "scp foo.jar [email protected]:"
            }
          }
        }

    • tabs

      The list of tabs displayed on the job detail page.

      /*
       * Copyright 2022 Thoughtworks, Inc.
       *
       * Licensed under the Apache License, Version 2.0 (the "License");
       * you may not use this file except in compliance with the License.
       * You may obtain a copy of the License at
       *
       *     http://www.apache.org/licenses/LICENSE-2.0
       *
       * Unless required by applicable law or agreed to in writing, software
       * distributed under the License is distributed on an "AS IS" BASIS,
       * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       * See the License for the specific language governing permissions and
       * limitations under the License.
       */


        job('build') {
          tabs {
            tab('JCoverage') {
              path = 'Jcoverage/index.html'
            }
            tab('JUnit') {
              path = 'junit/index.html'
            }
          }
        }

    • properties

      The list of properties published by this job

      /*
       * Copyright 2022 Thoughtworks, Inc.
       *
       * Licensed under the Apache License, Version 2.0 (the "License");
       * you may not use this file except in compliance with the License.
       * You may obtain a copy of the License at
       *
       *     http://www.apache.org/licenses/LICENSE-2.0
       *
       * Unless required by applicable law or agreed to in writing, software
       * distributed under the License is distributed on an "AS IS" BASIS,
       * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       * See the License for the specific language governing permissions and
       * limitations under the License.
       */


        job('build') {
          properties {
            property('coverage-percentage') {
              source = 'jcoverage.xml'
              xpath = '//report/coverage'
            }
            property('error-count') {
              source = 'junit-rport.xml'
              xpath = 'string(/testsuite/@errors)'
            }
          }
        }

    • getRunInstanceCount

      public Object getRunInstanceCount()
      The number of agents this job should run on. Defaults to 1. Set to string "all" to run on all agents.
    • getTimeout

      public Integer getTimeout()
      The job hung timeout (in minutes). If there is no console output for within this interval of time, the job is assumed to be jung and will be terminated by GoCD.

      Defaults to 0 to never timeout.

    • getElasticProfileId

      public String getElasticProfileId()
      A job can be configured to run on an elastic agent by specifying this attribute, which maps to the id of an existing <profile> defined in the main config xml. MUST NOT be specified along with resources
    • getResources

      public List<String> getResources()
      Specifies the list of resources that will be matched against jobs. An Agent must have all the Resources specified for a Job to be able to run this job. MUST NOT be specified along with elasticProfileId
    • setRunInstanceCount

      public void setRunInstanceCount(Object runInstanceCount)
      The number of agents this job should run on. Defaults to 1. Set to string "all" to run on all agents.
    • setTimeout

      public void setTimeout(Integer timeout)
      The job hung timeout (in minutes). If there is no console output for within this interval of time, the job is assumed to be jung and will be terminated by GoCD.

      Defaults to 0 to never timeout.

    • setElasticProfileId

      public void setElasticProfileId(String elasticProfileId)
      A job can be configured to run on an elastic agent by specifying this attribute, which maps to the id of an existing <profile> defined in the main config xml. MUST NOT be specified along with resources
    • setResources

      public void setResources(List<String> resources)
      Specifies the list of resources that will be matched against jobs. An Agent must have all the Resources specified for a Job to be able to run this job. MUST NOT be specified along with elasticProfileId
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class HasEnvironmentVariables<Job>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class HasEnvironmentVariables<Job>
    • toString

      public String toString()
      Overrides:
      toString in class HasEnvironmentVariables<Job>