簡體   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