Related
I need to have a dynamic stages creation. Depending on the list size, it will have X amount of stages. Each of them will have stages before for allocation and preparation. As they have to run parallel, those stages have to be executed on each test bot.
The issue I have is everything has to be in a Script block due to the dynamic stage creation, but I cannot use most of the stuff like agent, stage block and such in it.
java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [VersionNumber, archive, bat, build, catchError, checkout, compareVersions, container, containerLog, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, findFiles, gerritCheck, gerritComment, gerritReview, getContext, git, input, isUnix, jiraAddComment...
When you are in Scripted Syntax you can't use declarative syntax like agent. Instead of using agent use node
node('label') {
stage('Build') {
//Something
}
I use Jenkins CI/CD and do the building for the script below
def secret = 'server'
def server = 'jenkins#103.171.85.155'
def directory = 'wayshub-frontend'
def branch = 'master'
pipeline{
agent any
stages{
stage ('compose down and pull'){
steps{
sshagent([secret]) {
sh '''
ssh -o StrictHostkeyChecking=no ${server} << EOF
cd ${directory}
docker-compose down
docker system prune -f
git pull origin ${branch}
exit
EOF
'''
}
}
}
stage ('build images'){
steps{
sshagent([secret]) {
sh '''
ssh -o StrictHostkeyChecking=no ${server} << EOF
cd ${directory}
docker-compose build
exit
EOF
'''
}
}
}
stage ('deploy'){
steps{
sshagent([secret]) {
sh '''
ssh -o StrictHostkeyChecking=no ${server} << EOF
cd ${directory}
docker-compose up -d
exit
EOF
'''
}
}
}
}
}
i got error during build
Error build
java.lang.NoSuchMethodError: No such DSL method 'sshagent' found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, getContext, git, input, isUnix, junit, library, libraryResource, load, mail, milestone, node, parallel, powershell, properties, publishChecks, publishHTML, pwd, pwsh, readFile, readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step, timeout, timestamps, tm, tool, unarchive, unstable, unstash, validateDeclarativePipeline, waitUntil, warnError, withChecks, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, withGradle, wrap, writeFile, ws] or symbols [GitUsernamePassword, all, allBranchesSame, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, authorizationMatrix, batchFile, bitbucketServer, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildDiscarders, buildRetention, buildUser, buildingTag, builtInNode, caseInsensitive, caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, choice, choiceParam, cleanWs, clock, command, contributor, credentials, cron, crumb, culprits, defaultFolderConfiguration, defaultView, demand, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerServer, dockerTool, dockerfile, downstream, dumb, durabilityHint, email-ext, envVars, envVarsFilter, environment, equals, expression, extendedEmailPublisher, file, fileParam, filePath, fingerprint, fingerprints, frameOptions, freeStyle, freeStyleJob, fromDocker, fromScm, fromSource, git, gitBranchDiscovery, gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubExcludeArchivedRepositories, gitHubExcludeForkedRepositories, gitHubExcludePrivateRepositories, gitHubExcludePublicRepositories, gitHubForkDiscovery, gitHubIgnoreDraftPullRequestFilter, gitHubPullRequestDiscovery, gitHubSshCheckout, gitHubTagDiscovery, gitHubTopicsFilter, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody, gitHubTrustPermissions, gitTagDiscovery, gitUsernamePassword, github, githubProjectProperty, githubPush, gradle, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, isRestartedRun, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobBuildDiscarder, jobName, junitTestResultStorage, label, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, mailer, masterBuild, maven, maven3Mojos, mavenErrors, mavenGlobalConfig, mavenMojos, mavenWarnings, modernSCM, myView, namedBranchesDifferent, newContainerPerStage, node, nodeProperties, nonInheriting, none, not, organizationFolder, overrideIndexTriggers, paneStatus, parallelsAlwaysFailFast, parameters, password, pattern, permanent, pipeline, pipeline-model, pipeline-model-docker, pipelineTriggers, plainText, plugin, pollSCM, preserveStashes, projectNamingStrategy, proxy, pruneTags, queueItemAuthenticator, quietPeriod, rateLimit, rateLimitBuilds, recipients, requestor, resourceRoot, retainOnlyVariables, run, runParam, sSHLauncher, schedule, scmRetryCount, scriptApproval, scriptApprovalLink, search, security, shell, simpleBuildDiscarder, skipDefaultCheckout, skipStagesAfterUnstable, slave, sourceRegexFilter, sourceWildcardFilter, ssh, sshPublicKey, sshUserPrivateKey, standard, status, string, stringParam, suppressAutomaticTriggering, suppressFolderAutomaticTriggering, swapSpace, tag, teamSlugFilter, text, textParam, timestamper, timestamperConfig, timezone, tmpSpace, toolLocation, triggeredBy, unsecured, untrusted, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt, x509ClientCert, zip] or globals [currentBuild, docker, env, params, pipeline, scm]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:219)
Github repository : https://github.com/pinoezz/Jenkins-Frontend
Guess what's wrong please help
It seems you have not installed the sshagent plugin. Here is the documentation for the plugin. Go to manage Jenkins and make sure it's installed.
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
In the scripted pipeline, you can do it like -
timestamps {
node() {
currentBuild.description = "text"
currentBuild.displayName = "text"
}
}
You are trying to execute JobDSL in pipelineDSL. That won't work
The pipelineDSL syntax to edit the build description is
currentBuild.description = "my new description"
wrap it in a script block if you are using declarative pipeline
To parse build logs, you should use sh step return output
def myVar = sh (
script: 'echo "toto"',
returnStdout: true
).trim()
now on the myVar variable you can use regex
def myRegexResult = (myVar =~ /myRegex/)
Using the plugin: https://plugins.jenkins.io/groovy-postbuild/
def matcher = manager.getLogMatcher(".*Total time: (.*)\$")
if(matcher?.matches()) {
manager.addShortText(matcher.group(1), "grey", "white", "0px", "white")
}
I have a Jenkinsfile where the build and tests run on the same Slave.
My requirement is that the build must be on one Slave (say A) and the tests must run on another slave (say B).
I just setup the slave B and I can see both my slaves A and B in Jenkins->Manage nodes.
The problem is that the build stage works successfully , but my prepare_test and test stages are not executed on slave B.
Below are problems seen:
1.) I get the following error after the build stage is successful:
"java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, getContext, git, input, isUnix, junit, library, libraryResource, load, lock, mail, milestone, node, parallel, powershell, properties, publishHTML, pwd, readFile, readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step, svn, timeout, timestamps, tm, tool, unarchive, unstable, unstash, validateDeclarativePipeline, waitUntil, warnError, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [all, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, attach, authorizationMatrix, batchFile, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildTimestamp, buildTimestamp
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
"
2.) Do not see the stages 'prepare_test' and 'test' for my branch, while I can see the stage related to build.
Attached my jenkinsfile code:
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('build') {
agent {
docker {
image 'XYZ'
args '-v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '########################################## Building #########################################'
// trigger the build
sh 'scm-src/build.sh all-projects'
}
}
}
}
pipeline {
agent {
label 'laptop-hp'
}
stages {
stage('prepare_test') {
agent {
docker {
image 'ABC'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '####################################### Prepare Test Environment ############################'
sh 'scm-src/test.sh prepare'
}
}
stage('test') {
agent {
docker {
image 'ABC'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '########################################## Testing ##########################################'
sh 'scm-src/test.sh run'
}
}
}
}
The name of my slave B is 'laptop-hp' as seen in Jenkinsfile
Is there a problem with Jenkinsfile or do I miss some settings on my slave B ?
Regards
kdy
You cannot have more than one pipeline {} block in a Declarative Pipeline. The correct syntax is to append your test stages right after the build stage. Then define the parameter label for each stage within docker {} to run on the corresponding slave. Also, it is sufficient to add the option skipDefaultCheckout true once at the top-level of the pipeline.
Your pipeline should now look like:
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('build') {
agent {
docker {
image 'XYZ'
label 'slave-A'
args '-v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '########################################## Building #########################################'
// trigger the build
sh 'scm-src/build.sh all-projects'
}
}
stage('prepare_test') {
agent {
docker {
image 'ABC'
label 'laptop-hp'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '####################################### Prepare Test Environment ############################'
sh 'scm-src/test.sh prepare'
}
}
stage('test') {
agent {
docker {
image 'ABC'
label 'laptop-hp'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '########################################## Testing ##########################################'
sh 'scm-src/test.sh run'
}
}
}
}
While checking quality gate status in pipeine, getting following error.
Pipeline Code is below
stage('SonarQube') {
// Run the maven build
dir("xyz_7.6_Trunk/xyz-services"){
sh ' mvn -f pom.xml clean install -Dapp.server=jboss org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=http://10.11.135.66:9000 -Dsonar.scm.disabled=True -U'
}
}
stage('Quality Gate') {
timeout(time: 1, unit: ‘HOURS’) {
def qg = waitForQualityGate()
if (qg.status != ‘OK’) {
error “Pipeline aborted due to quality gate failure: ${qg.status}”
}
}
}
Error log is below.
java.lang.NoSuchMethodError: No such DSL method 'Time' 'HOURS' found among steps [acceptGitLabMR, addBadge, addErrorBadge, addGitLabMRComment, addHtmlBadge, addInfoBadge, addShortText, addWarningBadge, ansiblePlaybook, ansibleTower, ansibleVault, archive, artifactPromotion, bat, build, catchError, checkout, createSummary, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, ec2, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, getContext, git, gitChangelog, gitlabBuilds, gitlabCommitStatus, input, isUnix, junit, library, libraryResource, load, mail, milestone, nexusArtifactUploader, nexusPolicyEvaluation, nexusPublisher, node, parallel, powershell, properties, pwd, readFile, readTrusted, removeBadges,
As I see, you use scripted pipeline, so the syntax should be fine.
timeout functionality is implemented in Pipeline: Basic Steps plugin (part of Pipeline plugin). That's why I think that you need to reinstall those plugins and the issue should be fixed. Anyway, please check again the syntax of the timeout step.