[英]How to extract individual Pipeline names from .gitlab-ci.yml file?
I have two pipelines in my gitlab.yml file.我的 gitlab.yml 文件中有两个管道。 I want to extract the pipeline name individually in my python. I tried using the pyyamil package but it does not do anything specfically to every pipeline.
我想在我的 python 中单独提取管道名称。我尝试使用 pyyamil package 但它没有对每个管道做任何具体的事情。 Basically, code.py in SCAN1 pipeline should return 'SCAN1' and code.py in SCAN2 pipeline should return 'SCAN2'.
基本上,SCAN1 管道中的 code.py 应该返回“SCAN1”,而 SCAN2 管道中的 code.py 应该返回“SCAN2”。 I want to return a value which is specific to each pipeline to be used in the code
我想返回一个特定于要在代码中使用的每个管道的值
script SCAN1:
stage: test
tags:
- linux-default
script:
- bash exp.sh & python3 code.py
script SCAN2:
stage: test
tags:
- linux-default
script:
- bash exp.sh & python3 code.py
You can use predefined variables.您可以使用预定义的变量。 Have a look at https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
看看https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
In your case you can use CI_JOB_NAME
.在您的情况下,您可以使用
CI_JOB_NAME
。 It's just environment variable so in your python just get it by:它只是环境变量,所以在您的 python 中,只需通过以下方式获取它:
from os import getenv
job_name = getenv('CI_JOB_NAME')
print(job_name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.