Search code examples
jenkinsjenkins-pipelinejenkins-plugins

Jenkins - Nodelabelparameter plugin in declarative pipeline breaks checkout


I am struggling configuring the 'Nodelabelparameter' plugin on my Jenkins environment.

The setup is the following:

 - Master node

 - Slave 1 node (small machine)
 - Slave 2 node (small machine)
 - Slave 3 node (high performance machine)
 - Slave 4 node (high performance machine)
 - Slave 5 node (high performance machine)

There are jobs that should only run on the high performance machines. This machines are labelled accordingly but I would like to be able to choose on which one to run the job as a parameter.

Up until now the jobs had the slave assigned on the Jenkinsfile configuration and it works fine:

pipeline {
    agent { label 'Slave 4' }
    stages {
        stage('a') {
        ...
        }
        stage('b') {
        ...
        }
    ...
    }
}

My expectations with the Nodelabelparameter plugin would be to add a parameter 'NODE' within the web interface, choose the nodes I can select for the job, and at last to the change the configuration on my Jenkinsfile to something like

pipeline {
    agent { label "${params.NODE}" }

    stages {
        stage('a') {
        ...
        }
        stage('b') {
        ...
        }
    ...
    }
}

On the Jenkins web interface the change takes place. Now there is a 'Build with parameters' that sends you to a drop down menu with the options I've configured. But afterwards the initial checkout will fail. I have tried multiple combinations of this (like agent any, agent none, etc.) to no avail.

16:58:23  Started by user USER
16:58:23  Checking out git git@master:repo.git into /home/jenkins/workspace/PROJECT/job@script/b0d2c89e5ff583ddb071670fc0e708ec4cb59185589f30b01dba50dc91a782de to read config-files/jenkins/Jenkinsfile
16:58:23  The recommended git tool is: NONE
16:58:23  using credential gitlab_ssh-jenkins_butler
16:58:23  Wiping out workspace first.
16:58:23  Cloning the remote Git repository
16:58:23  Cloning repository git@master:repo.git
16:58:23   > git init /home/jenkins/workspace/PROJECT@script/b0d2c89e5ff583ddb071670fc0e708ec4cb59185589f30b01dba50dc91a782de # timeout=10
16:58:24  Fetching upstream changes from git@master:repo.git
16:58:24   > git --version # timeout=10
16:58:24   > git --version # 'git version 2.30.2'
16:58:24  using GIT_SSH to set credentials GitLab SSH jenkins_butler
16:58:24   > git fetch --tags --force --progress -- git@master:repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
16:58:41   > git config remote.origin.url git@master:repo.git # timeout=10
16:58:41   > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
16:58:41   > git config remote.origin.url git@master:repo.git # timeout=10
16:58:41  Fetching upstream changes from git@master:repo.git
16:58:41  using GIT_SSH to set credentials GitLab SSH jenkins_butler
16:58:41   > git fetch --tags --force --progress -- git@master:repo.git +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/* # timeout=10
16:58:41   > git rev-parse refs/remotes/origin/jenkins_parameter^{commit} # timeout=10
16:58:41  Checking out Revision 3e76105281220d53992b8147910846e23f80e0be (refs/remotes/origin/jenkins_parameter)
16:58:41   > git config core.sparsecheckout # timeout=10
16:58:41   > git checkout -f 3e76105281220d53992b8147910846e23f80e0be # timeout=10
16:58:43  Commit message: "jenkins test"
16:58:43   > git rev-list --no-walk fd0e85270e947242465dba0b68f195361074d634 # timeout=10
16:58:43   > git remote # timeout=10
16:58:43   > git submodule init # timeout=10
16:58:43  ERROR: Checkout failed
16:58:43  hudson.plugins.git.GitException: Command "git submodule init" returned status code 127:
16:58:43  stdout: 
16:58:43  stderr: /usr/lib/git-core/git-submodule: 7: sed: not found
16:58:43  /usr/lib/git-core/git-submodule: 86: /usr/lib/git-core/git-sh-setup: sed: not found
16:58:43  /usr/lib/git-core/git-submodule: 333: /usr/lib/git-core/git-sh-setup: uname: not found
16:58:43  /usr/lib/git-core/git-submodule: 954: sed: not found
16:58:43  /usr/lib/git-core/git-submodule: 954: cmd_: not found
16:58:43  
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2675)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2605)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2601)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1969)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1981)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.submoduleInit(CliGitAPIImpl.java:1308)
16:58:43    at org.jenkinsci.plugins.gitclient.LegacyCompatibleGitAPIImpl.setupSubmoduleUrls(LegacyCompatibleGitAPIImpl.java:100)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setupSubmoduleUrls(CliGitAPIImpl.java:85)
16:58:43    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setupSubmoduleUrls(CliGitAPIImpl.java:1840)
16:58:43    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:145)
16:58:43  Caused: java.io.IOException: Could not perform submodule update
16:58:43    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:165)
16:58:43    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1393)
16:58:43    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
16:58:43    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:159)
16:58:43    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:70)
16:58:43    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
16:58:43    at hudson.model.ResourceController.execute(ResourceController.java:101)
16:58:43    at hudson.model.Executor.run(Executor.java:442)
16:58:43  ERROR: Maximum checkout retry attempts reached, aborting
16:58:43  Finished: FAILURE

As the error is 127, I imagine it is not running where I think it should be running, but it really doesn't make sense to me as all nodes have the same git version. Also removing the 'submodule' checkout just makes the normal checkout fail.

This error happens as soon as I add the parameter on the Jenkins graphical interface. Even if I keep the original Jenkinsfile with the hardcoded node, the build will still fail on checkout.

Some answers on this topic go on defining the agent node per stage, but I would like to avoid that route if possible as my jobs need to run entirely on a single server.

What am I missing?


Solution

  • I ended up coming back to the same problem. In this case I managed to have a solution with a combination of other answers:

    • From here I added my configuration in the Jenkinsfile

      choice(name: 'node', choices: nodesByLabel('label'), description: 'The node to run on') 
      
    • From here I noticed I was missing the installation of the Pipeline Utility Steps plugin.

    • At last, almost one year have passed and multiple updates of Jenkins may have helped.