Use jobs.<job_id>
to assign a unique identifier to a workflow job. Replace <job_id>
with a string that uniquely identifies the job within the jobs
object. Reference this identifier in other jobs as needed.
The <job_id>
must start with a letter and may include only alphanumeric characters, hyphens (-
), or underscores (_
).
Usage example
The following example shows how to define a job using a unique job ID (my-job
) and how to reference it from another job (follow-up-job
) using the needs
keyword.
apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: My workflow on: push: branches: - '**' jobs: my-job: (1) steps: - name: Print greeting (2) uses: docker://alpine:3.18 run: echo "Hello world" follow-up-job: (3) needs: [my-job] (4) steps: - name: Print follow-up message (5) uses: docker://alpine:3.18 run: echo "my-job completed. Running next job."
1 | The job ID my-job uniquely identifies this job inside the jobs block. |
2 | This step runs a command inside an Alpine Linux container and prints "Hello world". |
3 | The job ID follow-up-job defines another job in the workflow. |
4 | The needs keyword specifies that follow-up-job depends on my-job . This ensures follow-up-job runs only after my-job completes successfully. |
5 | This step confirms that follow-up-job is executed after my-job and prints a follow-up message.. |