mjoubert (mjoubert)
mjoubert commented

Excellent, is this ready for me to sync and test ?

mjoubert (mjoubert)
mjoubert commented

ah, just saw your JIRA note stating it is ready for release.

mjoubert (mjoubert)
mjoubert commented

I have been trying to make this work....

if I modify the code to:
@Extension()
public class P4EnvironmentContributor extends EnvironmentContributor {

<a href="/@Override" target="_self">@Override</a>
public void buildEnvironmentFor(Run run, EnvVars env, TaskListener listener) throws IOException, InterruptedException {
    TagAction tagAction = run.getAction(TagAction.class);
    listener.getLogger().println(&quot;buildEnvironmentFor&quot;);

Then I can see the "buildEnvironmentFor" printed BEFORE the P4 step run.

Looking at the docs, this API is called at the beginning of a well written workflow step to get the env variables.

But this doesn't set the env for main flow only for other steps that does call buildEnvironmentFor.
The sh or batch step doesn't call buildEnvironmentFor either...

I want to do
currentBuild.displayName = "#${BUILD_NUMBER}.${env.P4_CHANGELIST}"
for example...

how do I get the env back ? (without writing my own step?)

mjoubert (mjoubert)
mjoubert commented

found it...
currentBuild.getRawBuild().getEnvironment()

paul_allen (Paul Allen)
Paul Allen commented

The extension point is called multiple times during a build and as so the environment changes. I would only attempt to use this after the sync. I'm not sure what you are trying to do, it looks like you are trying to access old builds?

mjoubert (mjoubert)
mjoubert commented

I have now got my head around on how the extension point works.
The problem was to get to currentBuild.getRawBuild().getEnvironment() without good documentation.
just using env doesn't work.
I can now proceed to pull the values out