Could use Jenkins description setter plugin
in Jenkins UI to set the build description to the matched regex from build logs, but I failed to replicate the same functionality as Jenkins script, used the below lines but ended up with errors.
publishers {
buildDescription(/^build-descrip: (.*)/)
}
O/p
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method 'publishers' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, VersionNumber, addInteractivePromotion, ansiColor, archive, artifactoryDistributeBuild, artifactoryDownload, artifactoryEditProps, artifactoryMavenBuild, artifactoryNpmInstall, artifactoryNpmPublish, artifactoryPromoteBuild, artifactoryUpload, bat, build, catchError, checkout, collectEnv, conanAddRemote, conanAddUser, container, containerLog, deleteDir, deployArtifacts, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, dockerPullStep, dockerPushStep, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, findFiles, getArtifactoryServer, getContext, git, initConanClient, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, lock, logstash, logstashSend, mail, milestone, newArtifactoryServer, newBuildInfo, newGradleBuild, newMavenBuild, newNpmBuild, node, nodesByLabel, parallel, podTemplate, powershell, properties, publishBuildInfo, publishHTML, pwd, readCSV, readFile, readJSON, readManifest, readMavenPom, readProperties, readTrusted, readYaml, resolveScm, retry, rtAddInteractivePromotion, rtBuildInfo, rtDeleteProps, rtDockerPush, rtDownload, rtGradleDeployer, rtGradleResolver, rtGradleRun, rtMavenDeployer, rtMavenResolver, rtMavenRun, rtNpmDeployer, rtNpmInstall, rtNpmPublish, rtNpmResolver, rtPromote, rtPublishBuildInfo, rtServer, rtSetProps, rtUpload, runConanCommand, script, sh, sha1, slackSend, sleep, sloccountPublish, sshagent, stage, stash, step, svn, tee, timeout, tm, tool, touch, unarchive, unstable, unstash, unzip, vSphere, validateDeclarativePipeline, waitUntil, warnError, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeCSV, writeFile, writeJSON, writeMavenPom, writeYaml, ws, xrayScan, xrayScanBuild, zip] or symbols [all, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, attach, authorizationMatrix, batchFile, bitbucket, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildAllBranches, buildAnyBranches, buildButton, buildChangeRequests, buildDescription, buildDiscarder, buildName, buildNamedBranches, buildNoneBranches, buildParameter, buildRegularBranches, buildTags, buildingTag, caseInsensitive, caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, choice, choiceParam, cleanWs, clock, cloud, command, configFile, configFileProvider, configMapVolume, containerEnvVar, containerLivenessProbe, containerTemplate, copyArtifactPermission, copyArtifacts, credentials, cron, crumb, culprits, default, defaultView, demand, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerfile, downloadSettings, downstream, dumb, durabilityHint, elasticSearch, emptyDirVolume, emptyDirWorkspaceVolume, envVar, envVars, environment, equals, exact, expression, extendedChoice, file, fileParam, filePath, findText, fingerprint, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubForkDiscovery, gitHubTagDiscovery, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody, gitHubTrustPermissions, gitParameter, github, githubPush, globalConfigFiles, gradle, headRegexFilter, headWildcardFilter, hostPathVolume, hostPathWorkspaceVolume, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, isRestartedRun, jacoco, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobName, kubernetes, label, lastCompleted, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, lastSuccessful, lastWithArtifacts, latestSavedBuild, legacy, legacySCM, list, local, location, logParser, logRotator, loggedInUsersCanDoAnything, logstash, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, msbuild, msbuildError, msbuildWarning, myView, never, newContainerPerStage, nfsVolume, nfsWorkspaceVolume, node, nodeProperties, nonInheriting, nonStoredPasswordParam, none, not, onFailure, overrideIndexTriggers, paneStatus, parallelsAlwaysFailFast, parameters, password, pattern, permalink, permanent, persistentVolumeClaim, persistentVolumeClaimWorkspaceVolume, pipeline-model, pipelineTriggers, plainText, plugin, podAnnotation, podEnvVar, pollSCM, portMapping, preserveStashes, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, rabbitMq, rateLimitBuilds, recipients, redis, regex, remotingCLI, requestor, rule, run, runParam, s3CopyArtifact, s3Upload, schedule, scmRetryCount, scriptApprovalLink, search, secretEnvVar, secretVolume, security, shell, skipDefaultCheckout, skipStagesAfterUnstable, slackNotifier, slave, sourceRegexFilter, sourceWildcardFilter, specific, ssh, sshPublisher, sshPublisherDesc, sshTransfer, sshUserPrivateKey, stackTrace, standard, status, string, stringParam, swapSpace, syslog, tag, text, textParam, tmpSpace, toolLocation, triggeredBy, unsecured, upstream, [![upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, wil][1]][1]dcards, withAnt, workspace, zfs, zip] or globals
3
Answers
You are trying to execute JobDSL in pipelineDSL. That won’t work
The pipelineDSL syntax to edit the build description is
wrap it in a script block if you are using declarative pipeline
To parse build logs, you should use sh step return output
now on the myVar variable you can use regex
In the scripted pipeline, you can do it like –
Using the plugin: https://plugins.jenkins.io/groovy-postbuild/