【问题标题】:How programmatically to get Jenkins user id?如何以编程方式获取 Jenkins 用户 ID?
【发布时间】:2012-08-10 17:27:00
【问题描述】:

我想将启动 Jenkins 作业的人的用户 ID 传递给脚本。 'env' 的输出表明没有设置环境变量,'ant -v' 的输出表明没有设置任何属性。如何访问开始工作的人的用户 ID? (我知道触发器可以启动工作,但对于这个工作,它永远是一个人)。

【问题讨论】:

    标签: jenkins


    【解决方案1】:

    获取作业执行者:

    curl -s "${BUILD_URL}/api/json" | \
    python -c '\
        import json; \
        import sys; \
        obj = json.loads(sys.stdin.read()); \
        print [ \
            cause["userId"] \
            for action in obj["actions"] \
            if "causes" in action \
            for cause in action["causes"] \
            if "userId" in cause][0];'
    

    另请参阅How to set environment variables in Jenkins?,它解释了如何将其传递到脚本中。

    【讨论】:

    • 我必须将 --user username:password 作为附加参数传递给 curl。
    【解决方案2】:
    BUILD_START_USER=`curl ${JOB_URL}'lastBuild/api/json' | python -c 'import json,sys;obj=json.loads(sys.stdin.read());print obj["'"actions"'"][1]["'"causes"'"][0]["'"userId"'"]'`
    

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多