繁体   English   中英

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

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

我有一个如下所示的 jenkins 共享库脚本,我想根据用户的 email 地址获取用户的 slackID,以便将此 ID 作为参数传递给 function。

如何根据 email 地址获取 slackID,然后将此值作为参数传递? 做这个的最好方式是什么?

这是共享库脚本。

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

项目 Jenkinsfile

sendNotifications(authorSlackID)

您可以像这样获得相应的 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