我计划在CI流水线中对拉取请求进行一些验证,根据验证结果,我希望自动创建问题并将其分配给开发人员。
这个功能在GitLab流水线中是可以实现的吗?
谢谢!
import gitlab
import os
gl = gitlab.Gitlab(os.environ['CI_SERVER_URL'], private_token=os.environ['PRIVATE_TOKEN'])
project = gl.projects.get(os.environ['CI_PROJECT_ID'])
issue_details = {
'title': f'Validation failed in {os.environ["CI_PROJECT_NAME"]}',
'description': f'Pipeline: {os.environ["CI_PIPELINE_URL"]}',
'assignee_ids': [111, 222]
}
issue = project.issues.create(issue_details )
PRIVATE_TOKEN
的掩码变量。其他变量是预定义变量。gitlab-ci.yml
中像这样调用它:# Use whatever image you need, but make sure it has Python installed
image: python:3.7
...
handle-failure:
when: on_failure
before_script:
- pip install -r ./cicd/gitlab/requirements.txt
script:
- python -m ./cicd/gitlab/create_issue.py