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).

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had to pass --user username:password as an additional argument to curl.
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"'"]'` 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.