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