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

问题描述

对于jenkins共享库,我有一个如下所示的脚本,我想根据用户的电子邮件地址获取用户的slackID,以将该ID作为参数传递给函数

如何根据电子邮件地址获取slackID,然后将该值作为参数传递?最好的方法是什么?

这是共享库脚本。

users = [
    bennytheball: [
        git: '[email protected]',slack: '12345ABCD'
    ],choochoo: [
        git: '[email protected]',slack: 'ABCD12345'
    ],topcat: [
        git: '[email protected]',slack: 'U9X76IJYA'
    ]
]

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

Jenkinsfile项目

sendNotifications(authorSlackID)

解决方法

您可以像这样获得相应的松弛ID

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