@Override
    public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException {
        Computer c = Computer.currentComputer();
        if (c != null) {
            EnvVars compEnv = c.getEnvironment().overrideAll(env);
            env.putAll(compEnv);
        }
        env.put("BUILD_DISPLAY_NAME", r.getDisplayName());

        Jenkins j = Jenkins.get();
        String rootUrl = j.getRootUrl();
        if (rootUrl != null) {
            env.put("BUILD_URL", rootUrl + r.getUrl());
        }
    }
@Issue("JENKINS-19307")
    @Test
    public void buildEnvironmentForJobShouldntUseCurrentComputer() throws IOException, InterruptedException {
        Computer computer = mock(Computer.class);
        Jenkins jenkins = mock(Jenkins.class);
        try (
                MockedStatic<Jenkins> mocked = mockStatic(Jenkins.class);
                MockedStatic<Computer> mockedComputer = mockStatic(Computer.class)
        ) {
            mocked.when(Jenkins::get).thenReturn(jenkins);
            mocked.when(Computer::currentComputer).thenReturn(computer);

            when(jenkins.getRootDir()).thenReturn(new File("."));

            EnvVars env = new EnvVars();
            instance.buildEnvironmentFor(job, env, listener);

            // currentComputer shouldn't be called since it relates to a running build,
            // which is not the case for calls of this method (e.g. polling)
            mockedComputer.verify(Computer::currentComputer, times(0));
            Computer.currentComputer();
        }
    }