jenkinsci / rake-plugin

Home Page:https://plugins.jenkins.io/rake/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rake can be run on the wrong executor if concurrent builds are enabled

rohanpm opened this issue · comments

Rake can be scheduled on the wrong machine.

To reproduce:

  • Create a job with "Execute concurrent builds if necessary" enabled
  • Add build steps:
    • Shell build step: echo 'task(:default) { puts hostname; sleep 8 }' > Rakefile
    • A few rake build steps (e.g. 5) with all options as default
  • Ensure you have enough executors available, on different hosts, to run at least two instances of the job at once
  • Trigger the job several times
  • In the logs, observe that rake may switch between hosts during the build, as in the following example:
Started by user Rohan McGovern
Started by user Rohan McGovern
[EnvInject] - Loading node environment variables.
Building remotely on rmcgover-ws-02 (docker) in workspace /home/jenkins/workspace/rake test
[rake test] $ /bin/sh -xe /tmp/hudson1005075034362718171.sh
+ echo 'task(:default) { puts `hostname`; sleep 8 }'
[rake test] $ /usr/bin/rake
dd8166383c1d
[rake test] $ /usr/bin/rake
dd8166383c1d
[rake test] $ /usr/bin/rake
5ea60c3d5e02
[rake test] $ /usr/bin/rake
5ea60c3d5e02
[rake test] $ /usr/bin/rake
5ea60c3d5e02
[rake test] $ /usr/bin/rake
5ea60c3d5e02
Finished: SUCCESS

I'm not too familiar with Jenkins' APIs, but to me, this code in Rake.java looks suspicious:

    private Launcher getLastBuiltLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) {
        AbstractProject project = build.getProject();
        Node lastBuiltOn = project.getLastBuiltOn();
        Launcher lastBuiltLauncher = launcher;
        if (lastBuiltOn != null) {
            lastBuiltLauncher = lastBuiltOn.createLauncher(listener);
        }

        return lastBuiltLauncher;
    }

... since the value of project.getLastBuiltOn() presumably can change during a build.