繁体   English   中英

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

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

我没有设法在.gitlab-ci.yml文件中声明全局变量,并通过python脚本为其分配值。 我想从.ini文件中提取一个值,并将其分配给yaml中的变量,这样我就可以在所有作业中使用它。

无论是否使用变量:在yaml文件中仍使用pyyaml进行管理。

在YAML文件中,我尝试以下操作将Python脚本的输出保存到YAML变量中。 一旦在变量下...:

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

...然后在before_script下:

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

以下PYTHON脚本返回一个我想分配给YAML变量appIdentifier的值(字符串)。 在这种情况下,输出是网络挂钩:

    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()

因此,yaml文件中的变量应如下所示:appIdentifier:web-hook

至少对我来说,解决方案如下:

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')

这使我可以在所有后续阶段中访问变量。

谢谢

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM