github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/jobs.md (about)

     1  # ProwJobs
     2  
     3  For a brief overview of how Prow runs jobs take a look at ["Life of a Prow Job"](/prow/life_of_a_prow_job.md).
     4  
     5  ## How to configure new jobs
     6  
     7  To configure a new job you'll need to add an entry into [config.yaml](/prow/config.yaml).
     8  If you have [update-config](/prow/plugins/updateconfig) plugin deployed then the
     9  config will be automatically updated once the PR is merged, else you will need
    10  to run `make update-config`. This does not require redeploying any binaries,
    11  and will take effect within a minute.
    12  
    13  Periodic config looks like so:
    14  
    15  ```yaml
    16  periodics:
    17  - name: foo-job         # Names need not be unique, but must match the regex ^[A-Za-z0-9-._]+$
    18    decorate: true        # Enable Pod Utility decoration. (see below)
    19    interval: 1h          # Anything that can be parsed by time.ParseDuration.
    20    spec: {}              # Valid Kubernetes PodSpec.
    21  ```
    22  
    23  Postsubmit config looks like so:
    24  
    25  ```yaml
    26  postsubmits:
    27    org/repo:
    28    - name: bar-job         # As for periodics.
    29      decorate: true        # As for periodics.
    30      spec: {}              # As for periodics.
    31      max_concurrency: 10   # Run no more than this number concurrently.
    32      branches:             # Regexps, only run against these branches.
    33      - ^master$
    34      skip_branches:        # Regexps, do not run against these branches.
    35      - ^release-.*$
    36  ```
    37  
    38  Postsubmits are run when a push event happens on a repo, hence they are
    39  configured per-repo. If no `branches` are specified, then they will run against
    40  every branch.
    41  
    42  Presubmit config looks like so:
    43  
    44  ```yaml
    45  presubmits:
    46    org/repo:
    47    - name: qux-job            # As for periodics.
    48      decorate: true           # As for periodics.
    49      always_run: true         # Run for every PR, or only when requested.
    50      run_if_changed: "qux/.*" # Regexp, only run on certain changed files.
    51      skip_report: true        # Whether to skip setting a status on GitHub.
    52      context: qux-job         # Status context. Defaults to the job name.
    53      max_concurrency: 10      # As for postsubmits.
    54      spec: {}                 # As for periodics.
    55      branches: []             # As for postsubmits.
    56      skip_branches: []        # As for postsubmits.
    57      trigger: "(?m)qux test this( please)?" # Regexp, see discussion.
    58      rerun_command: "qux test this please"  # String, see discussion.
    59  ```
    60  
    61  If you only want to run tests when specific files are touched, you can use
    62  `run_if_changed`. A useful pattern when adding new jobs is to start with
    63  `always_run` set to false and `skip_report` set to true. Test it out a few
    64  times by manually triggering, then switch `always_run` to true. Watch for a
    65  couple days, then switch `skip_report` to false.
    66  
    67  The `trigger` is a regexp that matches the `rerun_command`. Users will be told
    68  to input the `rerun_command` when they want to rerun the job. Actually, anything
    69  that matches `trigger` will suffice. This is useful if you want to make one
    70  command that reruns all jobs. If unspecified, the default configuration makes
    71  `/test <job-name>` trigger the job.
    72  
    73  ### Pod Utilities
    74  
    75  If you are adding a new job that will execute on a Kubernetes cluster (`agent: kubernetes`, the default value) you should consider using the [Pod Utilities](/prow/pod-utilities.md). The pod utils decorate jobs with additional containers that transparently provide source code checkout and log/metadata/artifact uploading to GCS.
    76  
    77  
    78  ## Job Environment Variables
    79  
    80  Prow will expose the following environment variables to your job. If the job
    81  runs on Kubernetes, the variables will be injected into every container in
    82  your pod, If the job is run in Jenkins, Prow will supply them as parameters to
    83  the build.
    84  
    85  Variable | Periodic | Postsubmit | Batch | Presubmit | Description | Example
    86  --- |:---:|:---:|:---:|:---:| --- | ---
    87  `JOB_NAME` | ✓ | ✓ | ✓ | ✓ | Name of the job. | `pull-test-infra-bazel`
    88  `JOB_TYPE` | ✓ | ✓ | ✓ | ✓ | Type of job. | `presubmit`
    89  `JOB_SPEC` | ✓ | ✓ | ✓ | ✓ | JSON-encoded job specification. | see below
    90  `BUILD_ID` | ✓ | ✓ | ✓ | ✓ | Unique build number for each run. | `12345`
    91  `PROW_JOB_ID` | ✓ | ✓ | ✓ | ✓ | Unique identifier for the owning Prow Job. | `1ce07fa2-0831-11e8-b07e-0a58ac101036`
    92  `REPO_OWNER` | | ✓ | ✓ | ✓ | GitHub org that triggered the job. | `kubernetes`
    93  `REPO_NAME` | | ✓ | ✓ | ✓ | GitHub repo that triggered the job. | `test-infra`
    94  `PULL_BASE_REF` | | ✓ | ✓ | ✓ | Ref name of the base branch. | `master`
    95  `PULL_BASE_SHA` | | ✓ | ✓ | ✓ | Git SHA of the base branch. | `123abc`
    96  `PULL_REFS` | | ✓ | ✓ | ✓ | All refs to test. | `master:123abc,5:qwe456`
    97  `PULL_NUMBER` | | | | ✓ | Pull request number. | `5`
    98  `PULL_PULL_SHA` | | | | ✓ | Pull request head SHA. | `qwe456`
    99  
   100  Examples of the JSON-encoded job specification follow for the different
   101  job types:
   102  
   103  Periodic Job:
   104  ```json
   105  {"type":"periodic","job":"job-name","buildid":"0","prowjobid":"uuid","refs":{}}
   106  ```
   107  
   108  Postsubmit Job:
   109  ```json
   110  {"type":"postsubmit","job":"job-name","buildid":"0","prowjobid":"uuid","refs":{"org":"org-name","repo":"repo-name","base_ref":"base-ref","base_sha":"base-sha"}}
   111  ```
   112  
   113  Presubmit Job:
   114  ```json
   115  {"type":"presubmit","job":"job-name","buildid":"0","prowjobid":"uuid","refs":{"org":"org-name","repo":"repo-name","base_ref":"base-ref","base_sha":"base-sha","pulls":[{"number":1,"author":"author-name","sha":"pull-sha"}]}}
   116  ```
   117  
   118  Batch Job:
   119  ```json
   120  {"type":"batch","job":"job-name","buildid":"0","prowjobid":"uuid","refs":{"org":"org-name","repo":"repo-name","base_ref":"base-ref","base_sha":"base-sha","pulls":[{"number":1,"author":"author-name","sha":"pull-sha"},{"number":2,"author":"other-author-name","sha":"second-pull-sha"}]}}
   121  ```
   122  
   123  ## Testing a new job
   124  
   125  See ["How to test a ProwJob"](/prow/build_test_update.md#How-to-test-a-ProwJob).