Build on all agents

955 views
Skip to first unread message

pe...@pjksolutions.com

unread,
Apr 6, 2021, 4:35:51 PM4/6/21
to Jenkins Users

Hi all, I have one master Jenkins CI server and four slaves is is possible to build a project on all agents simultaneously ?

Mark Waite

unread,
Apr 6, 2021, 4:47:19 PM4/6/21
to Jenkins Users
Yes.  The Jenkins Pipeline can request to build on all available agents or on all agents that match a specific label.  See nodesByLabel.

Here's an example:

def nodes = nodesByLabel label: '!windows'
nodes = nodes.sort()

Map tasks = [:]

for (int i = 0; i < nodes.size(); i++) {
    def label = nodes[i]
    def stageName = 'Check git cache ' + label.replaceAll('(-jagent)|(-ssh)|(-mwaite)|(.markwaite.net)|(-beemarkwaite)|(-jenkins)', '')
    tasks[label] = {
        node(label) {
            stage(stageName) {
                if (isUnix()) {
                    sh '[ -d /var/lib/git/mwaite ] || (echo /var/lib/git/mwaite directory not found; exit 1)'
                } else {
                    bat 'echo git cache check not implemented for Windows'
                }
            }
        }
    }
}

timeout(time: 3, unit: 'MINUTES') {
    parallel(tasks)
}

Jenkins multi-configuration jobs can also build on all agents that match a particular label, using either the elastic axis plugin or the node label parameters plugin.

Mark Waite

On Tue, Apr 6, 2021 at 2:36 PM pe...@pjksolutions.com <pe...@pjksolutions.com> wrote:

Hi all, I have one master Jenkins CI server and four slaves is is possible to build a project on all agents simultaneously ?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e974d160-b2b1-41ca-b23a-5f5ef296831en%40googlegroups.com.

pe...@pjksolutions.com

unread,
Apr 10, 2021, 4:33:32 PM4/10/21
to Jenkins Users
Thanks Mark, where do I run that code ?

Mark Waite

unread,
Apr 10, 2021, 4:58:43 PM4/10/21
to Jenkins Users
The sample that I provided would be placed in a file named 'Jenkinsfile' at the root of a git repository, then a Pipeline job should be defined in Jenkins for that git repository.

pe...@pjksolutions.com

unread,
Apr 12, 2021, 11:36:38 AM4/12/21
to Jenkins Users
Hi Mark I tried to run it and got  java.lang.NoSuchMethodError: No such DSL method 'nodesByLabel' and a lot more errors 

pe...@pjksolutions.com

unread,
Apr 12, 2021, 11:41:03 AM4/12/21
to Jenkins Users
The complete error dump
java.lang.NoSuchMethodError: No such DSL method 'nodesByLabel'
found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, emailextrecipients,
 envVarsForTool, error, fileExists, findBuildScans, getContext, git, input, isUnix, junit, library, libraryResource,
 load, lock, mail, milestone, node, parallel, powershell, properties, publishChecks, 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, withEnv, withGradle, wrap,
 writeFile, ws] or symbols [all, allBranchesSame, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf,
 apiToken, architecture, archiveArtifacts, artifactManager, authorizationMatrix, batchFile, booleanParam, branch, brokenBuildSuspects,
 brokenTestsSuspects, buildButton, buildDiscarder, buildDiscarders, buildRetention, buildUser, buildingTag, caseInsensitive,
 caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, choice, choiceParam, cleanWs, clock,
 command, credentials, cron, crumb, culprits, defaultFolderConfiguration, defaultView, demand, developers, disableConcurrentBuilds,
 disableResume, downstream, dumb, durabilityHint, email-ext, envVars, envVarsFilter, environment, equals, expression, extendedEmailPublisher,
 file, fileParam, filePath, fingerprint, fingerprints, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, gitBranchDiscovery,
 gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubExcludeArchivedRepositories, gitHubExcludePublicRepositories, gitHubForkDiscovery,
 gitHubPullRequestDiscovery, gitHubSshCheckout, gitHubTagDiscovery, gitHubTopicsFilter, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody,
 gitHubTrustPermissions, gitTagDiscovery, github, 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, node, nodeProperties, nonInheriting, none, not, overrideIndexTriggers, paneStatus, parallelsAlwaysFailFast,
 parameters, password, pattern, permanent, 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, swapSpace, tag, teamSlugFilter, text, textParam, timestamper, timestamperConfig, timezone, tmpSpace, toolLocation,
 triggeredBy, unsecured, untrusted, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt,
 zip] or globals [currentBuild, env, params, pipeline, scm]

Mark Waite

unread,
Apr 12, 2021, 12:54:54 PM4/12/21
to Jenkins Users
The Jenkins Pipeline DSL is extensible.  It is extended by Jenkins plugins that you may choose to install.  The nodesByLabel step is provided by the Pipeline utility steps plugin.  You'll need to install  the Pipeline utility steps plugin in order to use that step.

pe...@pjksolutions.com

unread,
Apr 14, 2021, 3:00:18 AM4/14/21
to Jenkins Users
HI Mark your code now runs as expected, now that I have a collection of nodes how can I use them to build a specific job ?

Mark Waite

unread,
Apr 15, 2021, 12:18:17 AM4/15/21
to Jenkins Users
See the parallel step

Reply all
Reply to author
Forward
0 new messages