-
Bug
-
Resolution: Not A Defect
-
Major
-
None
-
Jenkins 2.414.3
- Jenkinsfile
@Library("jenkins-lib@main") _ import sam.jenkins.Slack import sam.jenkins.Rancher import sam.jenkins.JenkinsUtils properties([ parameters([ string(name: 'ENV', defaultValue: ''), string(name: 'GIT_PARANT_REPO', defaultValue: ''), string(name: 'GIT_REPO', defaultValue: ''), string(name: 'GIT_BRANCH', defaultValue: ''), string(name: 'IMAGE_TAG', defaultValue: ''), string(name: 'SLACK_CHANNEL_ID', defaultValue: ''), string(name: 'SLACK_PM', defaultValue: ''), string(name: 'SLACK_TRIGGER_USER_ID', defaultValue: ''), string(name: 'SLACK_CREDENTIAL_ID', defaultValue: ''), string(name: 'GIT_CREDENTIAL_ID', defaultValue: ''), string(name: 'ACR_CREDENTIAL_ID', defaultValue: ''), string(name: 'RANCHER_CREDENTIAL_ID', defaultValue: ''), string(name: 'AZURE_PAT_ID', defaultValue: ''), string(name: 'ACR_ENDPOINT', defaultValue: ''), string(name: 'RANCHER_URL', defaultValue: ''), string(name: 'MIGRATION', defaultValue: 'false'), ]) ]) JenkinsUtils jenkinsUtils = new JenkinsUtils(steps) Slack slack = new Slack(credentialId = params.SLACK_CREDENTIAL_ID, channel = params.SLACK_CHANNEL_ID) Rancher rancher = new Rancher(credentialId = params.RANCHER_CREDENTIAL_ID) String workDir String apiDir String projectName String projectUrl String gitCommitHash String feedInfo List slackUserIds = [] slackUserIds.add(params.SLACK_TRIGGER_USER_ID) node () { // Clone stage stage("Clone") { ... jenkinsUtils.clone( gitCradentialId = params.GIT_CREDENTIAL_ID, gitProjectName = params.GIT_REPO, repoName = params.GIT_REPO, gitBranch = params.GIT_BRANCH ) workDir="${WORKSPACE}" ... } dir("${workDir}"){ stage("Pre-Build"){ ... slack.sendSlackInitMessage( slackUserIds = slackUserIds, jobName = JOB_NAME, buildNumber = BUILD_NUMBER, env=params.ENV, gitBranch = params.GIT_BRANCH, imageTag = params.IMAGE_TAG, buildUrl = BUILD_URL ) ... } // Build stage stage("Build") { try { if (params.MIGRATION == "only"){ return } if (params.ENV == "production") { dotnetBuildEnv = "Release" } else { dotnetBuildEnv = "Development" } docker.withRegistry("http://${params.ACR_ENDPOINT}", params.ACR_CREDENTIAL_ID) { def image = docker.build("${params.GIT_REPO}_${params.ENV}","-f ${apiDir}/Dockerfile --build-arg ENV_STAGE=${params.ENV} --build-arg BUILD_CONFIGURATION=${dotnetBuildEnv} --build-arg VSS_NUGET_EXTERNAL_FEED_ENDPOINTS=${feedInfo} .") image.tag("${params.IMAGE_TAG}_${gitCommitHash}") image.push("${params.IMAGE_TAG}_${gitCommitHash}") } } catch (Exception err) { slack.sendSlackFailMessage("Build failed\n```${err}```") throw(err) } } }
- Slack of library
package sam.jenkins @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1') import sam.jenkins.JenkinsUtils import groovyx.net.http.HTTPBuilder import groovyx.net.http.Method import groovyx.net.http.ContentType import java.nio.charset.StandardCharsets class Slack { private String token private String channel public String threadTs public List initMessage = [] Slack(String credentialId,String channel){ this.token = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.Credentials.class).find{ it.id == credentialId}.secret this.channel = channel } public void sendSlackInitMessage(List slackUserIds = [], String jobName, String buildNumber, String env, String gitBranch, String imageTag, String buildUrl) { slackUserIds.unique() String slackUserIdsStr = slackUserIds.collect { "<@$it>" }.join(" ") this.initMessage.add(createSectionMrkdwn("${slackUserIdsStr} 開始部署\n${jobName} #${buildNumber} ")) this.initMessage.add(createdivider()) this.initMessage.add(createSectionMrkdwn("ENV `${env}`\nBRANCH `${gitBranch}`\nIMAGE_TAG `${imageTag}`")) this.initMessage.add(createdivider()) this.initMessage.add(createSingleButton("Jenkins Log", "${buildUrl}/console")) this.threadTs = this.sendMessage(this.initMessage).ts reactionAdd("jenkins_triggered", this.threadTs) } @NonCPS public Map sendMessage(List blocks, String ts = 0) { def http = new HTTPBuilder('https://slack.com/api/chat.postMessage') Map responseMap http.request(Method.POST, ContentType.JSON) { req -> body = [blocks: blocks, channel: this.channel, ts: ts] headers.'Authorization' = "Bearer ${this.token}" headers.'Content-Type' = 'application/json' response.success = { resp, json -> JenkinsUtils.log("Response: ${json}") responseMap = json } response.failure = { resp, json -> JenkinsUtils.log("Failed with response: ${json}") } } return responseMap } }
- Full error log
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: aefe03f1-9486-4208-8d94-adac27ea2b45 groovy.lang.MissingPropertyException: No such property: NODE_NAME for class: java.lang.String at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:471) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39) at org.jenkinsci.plugins.workflow.cps.LoggingInvoker.getProperty(LoggingInvoker.java:121) at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20) at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:64) at org.jenkinsci.plugins.docker.workflow.Docker.withRegistry(Docker.groovy:38) at WorkflowScript.run(WorkflowScript:409) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:73) at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:65) at jdk.internal.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:152) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:423) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:331) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:295) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:97) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68) at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) Finished: FAILURE
I implemented a library for Slack. After calling slack.sendSlackInitMessage() in the Pre-Build stage then calling docker.withRegistry, the Docker Workflow Plugin returned an exception.