VERSION如何从 python 脚本中获取 gitlab-ci 环境变量值 -get_version.py对于可在 Windows 和 Linux 操作系统上运行的 gitlab-runners?我需要一些通用的解决方案,以便它可以在两种操作系统上运行。
这是我的.gitlab-ci.yml:
stages:
- versioning
variables:
VERSION: ""
versioning:
stage: versioning
script:
- echo "[versioning] ..."
- python ./ci-cd_scripts/get_version.py
- echo $VERSION
Run Code Online (Sandbox Code Playgroud)
这是我的./ci-cd_scripts/get_version.py:
import os
refName = os.environ.get("CI_COMMIT_REF_NAME")
piplineID = os.environ.get("CI_PIPELINE_ID")
relVersion = refName + ".0." + piplineID
version = relVersion.replace("rel.", "")
print("current version is", version)
Run Code Online (Sandbox Code Playgroud)