简体   繁体   English

Jenkins 根据条件获取 map 值并作为参数传递给共享库

[英]Jenkins fetch map value on condition and pass to shared library as parameter

I've a script like as below for jenkins shared library and I would like to get users's slackID according to the user's email adress for passing this ID as parameter to the function.我有一个如下所示的 jenkins 共享库脚本,我想根据用户的 email 地址获取用户的 slackID,以便将此 ID 作为参数传递给 function。

How can I fetch the slackID according to the email address and then pass this value as parameter?如何根据 email 地址获取 slackID,然后将此值作为参数传递? What is the best way to do this?做这个的最好方式是什么?

Here is the shared-library script.这是共享库脚本。

users = [
    bennytheball: [
        git: 'benny.ball@alley.way',
        slack: '12345ABCD'
    ],
    choochoo: [
        git: 'choo.choo@alley.way',
        slack: 'ABCD12345'
    ],
    topcat: [
        git: 'top.cat@alley.way',
        slack: 'U9X76IJYA'
    ]
]

String email = sh(script: 'git show -s --pretty=%ae', returnStdout: true).trim()
def sendBuildStatusOverSlack(String authorSlackID = null) {
         .....
    }

Project Jenkinsfile项目 Jenkinsfile

sendNotifications(authorSlackID)

You can get the according slack id like this您可以像这样获得相应的 slack id

users.findAll { _, contact -> contact.git == email }
     .collect { _, contact -> contact.slack } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM