有一个下一个字段,我试图将其工作的闲置结果发送出去
} finally {
sh(script: 'ls -lah')
slack.jobResultNotification(currentBuild.result, '#some_channel',null,null,null,'https://hooks.slack.com/services/XXXXXX/XXXXXX/XXXXXXX')
}
}
但是每次我得到
java.lang.NullPointerException: Cannot invoke method getSecret() on null object
松弛通知功能(我只添加了代码的重要部分)
def jobResultNotification(String buildStatusParam, String channel = "#some_channel",
String jobName=null,
Number buildNumber=null, String buildUrl=null,
String credentialsId="SLACK_WEBHOOK_URL") {
def jobNameParam = jobName != null && jobName != "" ? jobName : env.JOB_NAME
def buildUrlParam = buildUrl != null && buildUrl != "" ? buildUrl : env.BUILD_URL
def buildNumberParam = buildNumber != null && buildNumber != "" ? buildNumber : env.BUILD_NUMBER
def common = new com.Common()
cred = common.getCredentialsById(credentialsId)
hook_url_parsed = cred.getSecret().toString()
}
还有信誉
def getCredentialsById(String credsId, String credsType = 'any') {
def credClasses = [ // ordered by class name
sshKey : com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.class,
cert : com.cloudbees.plugins.credentials.common.CertificateCredentials.class,
password : com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class,
any : com.cloudbees.plugins.credentials.impl.BaseStandardCredentials.class,
dockerCert: org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials.class,
file : org.jenkinsci.plugins.plaincredentials.FileCredentials.class,
string : org.jenkinsci.plugins.plaincredentials.StringCredentials.class,
]
return com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
credClasses[credsType],
jenkins.model.Jenkins.instance
).findAll { cred -> cred.id == credsId }[0]
}