Checks for concurrent PipelineRuns on the same repository. If another run is already in progress, logs a message and exits gracefully. Prevents race conditions in release pipelines.
taskRef:
resolver: git
params:
- name: url
value: https://github.com/openlab-red/tekton-task-check-lock.git
- name: revision
value: main
- name: pathInRepo
value: task/check-lock.yaml
params:
- name: repo-url
value: $(params.repo-url)
- name: pipeline-name
value: "release-pipeline"| Name | Type | Default | Description |
|---|---|---|---|
repo-url |
string | required | Repository URL to match against other PipelineRuns |
pipeline-name |
string | required | Pipeline name to filter PipelineRuns |
fail-on-conflict |
string | false |
If true, fail with error. If false, exit 0 (skip gracefully) |
image |
string | quay.io/openlab-red/ci-tools:latest |
Image with oc/kubectl and jq |
| Scenario | Behavior |
|---|---|
| No concurrent runs | Logs "No concurrent runs detected", proceeds |
| Concurrent run detected | Logs "Another run is already in progress", exits 0 (skip) |
Concurrent run + fail-on-conflict=true |
Logs message, exits 1 (fail) |
The pipeline ServiceAccount needs permission to list PipelineRuns. The default pipeline ServiceAccount in OpenShift Pipelines already has this permission.
apiVersion: tekton.dev/v1
kind: Pipeline
spec:
params:
- name: repo-url
type: string
tasks:
- name: check-lock
taskRef:
resolver: git
params:
- name: url
value: https://github.com/openlab-red/tekton-task-check-lock.git
- name: revision
value: main
- name: pathInRepo
value: task/check-lock.yaml
params:
- name: repo-url
value: $(params.repo-url)
- name: pipeline-name
value: release-pipeline
- name: clone
runAfter:
- check-lock
# ... rest of pipeline- Task receives
repo-urlandpipeline-nameparams - Queries Kubernetes API for PipelineRuns with matching pipeline label
- Filters for runs with
status.conditions[0].reason == "Running" - Compares
repo-urlparam of each PipelineRun - Excludes the current PipelineRun from the list
- If another running PipelineRun with same repo-url is found:
- Logs the name of the conflicting run
- Exits 0 (graceful skip) or 1 (fail) based on
fail-on-conflict
- If no conflicts, proceeds normally