如何在GitLab管道中访问Jenkins环境变量?

时间:2019-08-14 10:52:36

标签: python jenkins

在我的GitLab管道中,调用了一个Python脚本,该脚本需要访问Jenkins环境变量JENKINS_BUILD_USER_CREDS_USR和JENKINS_BUILD_USER_CREDS_PSW,请参见代码。

我需要JENKINS_BUILD_USER_CREDS来进行httpResponse

userColonTokenUSR = os.environ.get('https://JENKINS_BUILD_USER_CREDS_USR@***/job/TESTJOBS/job/trigger_with_python')
userColonTokenPSW = os.environ.get('JENKINS_BUILD_USER_CREDS_PSW')
print(userColonTokenUSR, userColonTokenPSW)
httpResponse = build_functions.buildRequCall(
    shopFolder, requ_Payload, userColonTokenUSR, userColonTokenPSW)
trigger_jenkins_build_job:
  stage: trigger_jenkins_build
  script:
  - echo "Test Stage 2/3 - Trigger Jenkins Build"
  - python3.7 ./gitLabCI/trigger_jenkins_build.py $appIdentifier $egrocery_tag
  - echo " Test Stage 2/3 Done"
def trigger_jenkins_build(appIdentifier, egroceryTag):
    print('triggering Jenkins build directly for testing purpose')
    print(appIdentifier, egroceryTag)
    logging.basicConfig(format='%(levelname)s - %(message)s')
    shopFolder = globalVars.initialize_identifier_to_shop_folder(appIdentifier)
    git_tag = os.environ.get('CI_COMMIT_TAG')
    print(shopFolder)
    hybrisVersion = get_hybris_version.getHybrisVersion(appIdentifier)
    requ_Payload = build_functions.buildPayload(git_tag, hybrisVersion, egroceryTag, False)
    userColonTokenUSR = os.environ.get('https://JENKINS_BUILD_USER_CREDS_USR@***/job/TESTJOBS/job/trigger_with_python')
    userColonTokenPSW = os.environ.get('JENKINS_BUILD_USER_CREDS_PSW')
    print(userColonTokenUSR, userColonTokenPSW)

0 个答案:

没有答案