-
Description of the problem, including code/CLI snippetI’m trying to trigger a pipeline for a merge request using the python-gitlab package, but I’m encountering a 400 error with the message: "The resulting pipeline would have been empty." My GitLab CI configuration does not include any rules for the job, so I’m unsure why this error is occurring. Here’s the code I’m using: import gitlab
from .constants import URL, TOKEN, PROJECT_ID, MR_ID
gl = gitlab.Gitlab(url=URL, private_token=TOKEN)
response = gl.http_request(
"POST",
f"/projects/{PROJECT_ID}/merge_requests/{MR_ID}/pipelines",
timeout=60,
retry_transient_errors=True,
)
print(response)
And here’s my .gitlab-ci.yml configuration: pre-commit:
image: python:3.12-bookworm
before_script:
- apt update
- apt install -y --no-install-recommends pipx
- PATH="/root/.local/bin:$PATH"
- pipx install pre-commit
script:
- pre-commit run --all-files
Expected BehaviorThe pipeline should be triggered successfully, and the pre-commit job defined in the .gitlab-ci.yml file should run. Actual BehaviorThe pipeline fails to trigger, and I receive the following error: Traceback (most recent call last):
File "/Users/neXeacon/Desktop/marge-bot/test.py", line 7, in <module>
response = gl.http_request(
"POST",
f"/projects/{PROJECT_ID}/merge_requests/{MR_ID}/pipelines",
timeout=60,
retry_transient_errors=True,
)
File "/Users/neXeacon/Desktop/marge-bot/venv/lib/python3.13/site-packages/gitlab/client.py", line 773, in http_request
raise gitlab.exceptions.GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 400: {'base': ['The resulting pipeline would have been empty. Review the rules configuration for the relevant jobs.']}
Specifications
|
Beta Was this translation helpful? Give feedback.
-
|
This doesn't sound like a python-gitlab issue to me. Please look at: https://docs.gitlab.com/ee/api/merge_requests.html#create-merge-request-pipeline From the first part of the docs there it says: Create a new pipeline for a merge request. A pipeline created from this endpoint doesn’t run a regular branch/tag pipeline. To create jobs, configure .gitlab-ci.yml with only: [merge_requests]. Also look at https://docs.gitlab.com/ee/ci/yaml/ and search for merge_requests. Looks like it is required to have in the .gitlab-ci.yml a only: merge_requests in your config. Any reason to not use: https://python-gitlab.readthedocs.io/en/stable/gl_objects/merge_requests.html#merge-request-pipelines ? |
Beta Was this translation helpful? Give feedback.
-
|
Has rules in job or workflow, and child pipeline need to do. |
Beta Was this translation helpful? Give feedback.
This doesn't sound like a python-gitlab issue to me.
Please look at: https://docs.gitlab.com/ee/api/merge_requests.html#create-merge-request-pipeline
From the first part of the docs there it says:
Create a new pipeline for a merge request. A pipeline created from this endpoint doesn’t run a regular branch/tag pipeline. To create jobs, configure .gitlab-ci.yml with only: [merge_requests].
Also look at https://docs.gitlab.com/ee/ci/yaml/ and search for merge_requests. Looks like it is required to have in the .gitlab-ci.yml a only: merge_requests in your config.
Any reason to not use: https://python-gitlab.readthedocs.io/en/stable/gl_objects/merge_requests.html#merge-request-pipelines ?