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).
            Asked
            
        
        
            Active
            
        
            Viewed 4,115 times
        
    2 Answers
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.
- 
                    I had to pass --user username:password as an additional argument to curl. – dolphus333 Mar 29 '17 at 12:37
 
     
     
     
    