简体   繁体   English

如何从 .gitlab-ci.yml 文件中提取单个管道名称?

[英]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.

相关问题 在Gitlab中配置.gitlab-ci.yml文件以测试python代码 - Configuring .gitlab-ci.yml file in Gitlab to test python Codes 我的 first.gitlab-ci.yml 文件:如何在 CI/CD 中运行现有文件 - My first .gitlab-ci.yml file: How to run existing files in CI/CD 如何在 gitlab-ci.yml 中将 postgis 扩展添加到 postgresql 数据库 - How to add postgis extension to postgresql database in gitlab-ci.yml 如何解析我有权访问的所有存储库中的所有.gitlab-ci.yml 文件? - How to parse all the .gitlab-ci.yml files from all the repositories that i have access to? .gitlab-ci.yml 缓存/工件配置,用于根据条件为后续管道/阶段保存大型二进制文件 - .gitlab-ci.yml cache/artifact configuration for saving large binaries for subsequent pipeline/stages based on condition 使用 gitlab-ci.yml 管道测试 python 程序时出现问题 - Problem using MPI in a python program when testing it with a gitlab-ci.yml pipeline Gitlab Flask Page: Problems with installing python GDAL package for Frozen Flask Application with.gitlab-ci.yml file - Gitlab Flask Page: Problems with installing python GDAL package for Frozen Flask Application with .gitlab-ci.yml file 如何在 Gitlab 中为简单的 hello world 程序配置 gitlab-ci.yml - How do I configure gitlab-ci.yml for a simple hello world program in Gitlab 每个python脚本是否可以在.gitlab-ci.yml文件中填充变量? - Is it possible to fill a variable in the .gitlab-ci.yml file per python script? 如何避免在.gitlab-ci.yml的每个阶段之前安装requirements.txt? - How to avoid installing requirements.txt before every stage in .gitlab-ci.yml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM