简体   繁体   English

每个python脚本是否可以在.gitlab-ci.yml文件中填充变量?

[英]Is it possible to fill a variable in the .gitlab-ci.yml file per python script?

I do not manage to declare global variables in the .gitlab-ci.yml file and assign a value to them via python script. 我没有设法在.gitlab-ci.yml文件中声明全局变量,并通过python脚本为其分配值。 I want to extract a value from a .ini file and assign it to the variable in yaml so that I have it available in all jobs. 我想从.ini文件中提取一个值,并将其分配给yaml中的变量,这样我就可以在所有作业中使用它。

no matter if with variables: in the yaml file still with pyyaml I manage it. 无论是否使用变量:在yaml文件中仍使用pyyaml进行管理。

In the YAML FILE I tried the following to save the output of the Python script into the YAML variable. 在YAML文件中,我尝试以下操作将Python脚本的输出保存到YAML变量中。 Once under variables ...: 一旦在变量下...:

    variables:
        appIdentifier: "" #=python3.7 ./gitLabCI/fill_appIdentifier.py

... and once under before_script: ...然后在before_script下:

    befor_script:
            - appIdentifier=$(python3.7 ./gitLabCI/fill_appIdentifier.py)

The following PYTHON script returns a value (string) that I want to assign to the YAML variable appIdentifier. 以下PYTHON脚本返回一个我想分配给YAML变量appIdentifier的值(字符串)。 In this case the ouput is web-hook: 在这种情况下,输出是网络挂钩:

    def fill_appIdentifier():
        appIdentifier = None
        repoName = globalVars.initialize_repo_name()
        print("repo name: {0}".format(repoName))
        module = get_value_from_releasnotes.getValueFromReleasnotes('module', False)
        print('module: {0}'.format(module))
        if(repoName == 'spar-egrocery'):
            appIdentifier = module
            print(appIdentifier)
            return appIdentifier
        else:
            appIdentifier = repoName
            print(appIdentifier)
            return appIdentifier

    fill_appIdentifier()

So the variable in the yaml file should then look like this: appIdentifier: web-hook 因此,yaml文件中的变量应如下所示:appIdentifier:web-hook

the solution, at least for me, is the following: 至少对我来说,解决方案如下:

before_script:
- export appIdentifier=$(python3.7 ./gitLabCI/fill_appIdentifier.py)
- export autobuild=$(python3.7 ./gitLabCI/get_value_from_releasnotes.py 'auto-build')
- export egrocery_tag=$(python3.7 ./gitLabCI/get_value_from_releasnotes.py 'egrocery_tag')

This allows me to access the variables in all subsequent stages. 这使我可以在所有后续阶段中访问变量。

THX 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Gitlab中配置.gitlab-ci.yml文件以测试python代码 - Configuring .gitlab-ci.yml file in Gitlab to test python Codes 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-ci.yml:“脚本:-pytest”命令无法识别 - gitlab-ci.yml: 'script: -pytest' command is not recognized gitlab-ci.yml python -c'多行cmd'失败 - gitlab-ci.yml python -c 'multiple line cmd' failed 我的 first.gitlab-ci.yml 文件:如何在 CI/CD 中运行现有文件 - My first .gitlab-ci.yml file: How to run existing files in CI/CD 使用 gitlab-ci.yml 管道测试 python 程序时出现问题 - Problem using MPI in a python program when testing it with a gitlab-ci.yml pipeline 在.gitlab-ci.yml中使用apt-get install python包 - use apt-get install python packages in .gitlab-ci.yml 如何从 .gitlab-ci.yml 文件中提取单个管道名称? - How to extract individual Pipeline names from .gitlab-ci.yml file? 使用 pyyaml 的 Load.gitlab-ci.yml 失败,无法确定构造函数 - Load .gitlab-ci.yml with pyyaml fails with could not determine constructor 如何在 gitlab-ci.yml 中将 postgis 扩展添加到 postgresql 数据库 - How to add postgis extension to postgresql database in gitlab-ci.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM