如何知道哪个用户回答了 Jenkins-Pipeline 输入步骤?
How to know which user answered a Jenkins-Pipeline input step?
我有一个 Jenkinsfile 脚本,用于测试执行 SVN 合并的可能性,然后询问用户提交合并的权限。
我想知道回答 "input" 步骤的用户名,以便将其写入提交消息。
这可能吗?
这就是我想做的假设:
outcome = input message: 'Merge trunk into branch?', ok: 'Merge'
echo "User that allowed merge: ${outcome.user}"
目前不可能,目前 input step
答案中仅返回入口参数,如 source code 中所述:
// TODO: perhaps we should return a different object to allow the workflow to look up
// who approved it, etc?
switch (mapResult.size()) {
case 0:
return null; // no value if there's no parameter
case 1:
return mapResult.values().iterator().next();
default:
return mapResult;
}
如果您想限制哪些用户可以批准输入步骤,您可以使用 submitter
参数,例如:
input message: 'Approve ?', submitter: 'authorized-submitter'
编辑
自 2017 年 1 月起,现在可以请求发送其他参数。请参阅上面的 。
如果您关闭 groovy-sandbox
:
,则可以为例外情况执行此操作
try {
'Deploy to production?'
node {
sh 'echo deploying'
}
} catch(e) {
def user = e.getCauses()[0].getUser()
echo "Production deployment aborted by:\n ${user}"
}
input
步骤有一个可选的 submitterParameter
,它允许指定返回的 Map
的键,该键应包含提交输入对话框的用户:
If specified, this is the name of the return value that will contain the ID of the user that approves this input.
The return value will be handled in a fashion similar to the parameters
value.
Type: String
这看起来如下:
def feedback = input(submitterParameter: 'submitter', ...)
echo "It was ${feedback.submitter} who submitted the dialog."
P.S:如果有人对 full-fledged 代码片段感兴趣,返回用户对对话框的正面和负面反馈(以及超时),我请指向 our pipeline library.
如果您不要求输入任何参数,那么添加 submitterParameter 就可以了。它没有将其添加为 return 对象的参数,而是将 returned 对象转换为包含用户名的字符串。
def feedback = input(submitterParameter: 'submitter')
echo "It was ${feedback} who submitted the dialog."
我有一个 Jenkinsfile 脚本,用于测试执行 SVN 合并的可能性,然后询问用户提交合并的权限。
我想知道回答 "input" 步骤的用户名,以便将其写入提交消息。
这可能吗?
这就是我想做的假设:
outcome = input message: 'Merge trunk into branch?', ok: 'Merge'
echo "User that allowed merge: ${outcome.user}"
目前不可能,目前 input step
答案中仅返回入口参数,如 source code 中所述:
// TODO: perhaps we should return a different object to allow the workflow to look up
// who approved it, etc?
switch (mapResult.size()) {
case 0:
return null; // no value if there's no parameter
case 1:
return mapResult.values().iterator().next();
default:
return mapResult;
}
如果您想限制哪些用户可以批准输入步骤,您可以使用 submitter
参数,例如:
input message: 'Approve ?', submitter: 'authorized-submitter'
编辑
自 2017 年 1 月起,现在可以请求发送其他参数。请参阅上面的
如果您关闭 groovy-sandbox
:
try {
'Deploy to production?'
node {
sh 'echo deploying'
}
} catch(e) {
def user = e.getCauses()[0].getUser()
echo "Production deployment aborted by:\n ${user}"
}
input
步骤有一个可选的 submitterParameter
,它允许指定返回的 Map
的键,该键应包含提交输入对话框的用户:
If specified, this is the name of the return value that will contain the ID of the user that approves this input.
The return value will be handled in a fashion similar to theparameters
value.
Type: String
这看起来如下:
def feedback = input(submitterParameter: 'submitter', ...)
echo "It was ${feedback.submitter} who submitted the dialog."
P.S:如果有人对 full-fledged 代码片段感兴趣,返回用户对对话框的正面和负面反馈(以及超时),我请指向 our pipeline library.
如果您不要求输入任何参数,那么添加 submitterParameter 就可以了。它没有将其添加为 return 对象的参数,而是将 returned 对象转换为包含用户名的字符串。
def feedback = input(submitterParameter: 'submitter')
echo "It was ${feedback} who submitted the dialog."