2

I would like to pass the user id of the person who started a Jenkins job to a script. The output of 'env' indicates no environment variables are set and the output of 'ant -v' indicates no properties are set. How do I access the user id of the person that started a job? (I understand that triggers can start jobs, but for this job, it will always be a person).

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
Noel Yap
  • 18,822
  • 21
  • 92
  • 144

2 Answers2

3

To get the job executor:

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];'

Also see How to set environment variables in Jenkins? which explains how to pass it into a script.

Community
  • 1
  • 1
Noel Yap
  • 18,822
  • 21
  • 92
  • 144
0
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"'"]'`
sloth
  • 99,095
  • 21
  • 171
  • 219
Vasee
  • 1