In Jenkins, how do builds know who requested them?

后端 未结 6 1149
南旧
南旧 2021-01-04 01:09

I need to pass the username of the requestor of a build down to the script that is actually doing the work. Looking at the console output for a particular build, the first

6条回答
  •  盖世英雄少女心
    2021-01-04 01:36

    I managed to get it (on Jenkins 2.58):

    currentBuild.getRawBuild().getCauses()[0].getUserId()
    

    Of course you need to set permissions in Jenkins to be able to call these methods. It's not always the 0th Cause object you are looking for, e.g. it may be another one if you replay another user's build (did not test this).

提交回复
热议问题