One last attempt...
My step class will now appear as an option, however I don't see any way of setting environment variables with it. Is this possible?
I did try "def app = buildMasterSelectApplication2 applicationId: '1'" in the options but got an error message that this is not a valid option.
I have an alternative implementation using SimpleBuildWrapper that does set the environment variables. I'm happy with that as my fallback as I've spent enough time on this issue (and thanks for your advice), however the "global" options syntax does appeal.
pipeline {
agent any
options {
buildMasterSelectApplication2 applicationId: '1'
}
stages {
stage('main') {
steps {
echo "id = $BUILDMASTER_APPLICATION_ID"
}
}
}
}
public StepExecution start(StepContext context) throws Exception {
return new SelectApplicationPipeline.Execution(context, applicationId);
}
@Extension
public static class DescriptorImpl extends StepDescriptor {
@Override
public Set<? extends Class<?>> getRequiredContext() {
return new HashSet<>(Arrays.asList(Run.class));
// , Launcher.class, TaskListener.class));
}
@Override
public String getFunctionName() {
return "buildMasterSelectApplication2";
}
@Override
public String getDisplayName() {
return "BuildMaster: Select Application 2";
}
@Override
public boolean takesImplicitBlockArgument() {
return true;
}
}
public static class Execution extends SynchronousNonBlockingStepExecution<BuildMasterApplication> implements BuildMasterSelectApplication {
private final String applicationId;
public Execution(StepContext context, String applicationId) {
super(context);
this.applicationId = applicationId; }
@Override
protected BuildMasterApplication run() throws Exception {
BuildMasterApplication a = new BuildMasterApplication();
a.applicationId = Integer.valueOf(this.getApplicationId());
a.releaseNumber = "1.2.0";
// This doesn't appear to do anything
this.getContext().get(Run.class).addAction(new VariableInjectionAction("BUILDMASTER_APPLICATION_ID", String.valueOf(a.applicationId)));
return a;
}
}
}
public class VariableInjectionAction implements EnvironmentContributingAction {
private String key;
private String value;
public VariableInjectionAction(String key, String value) {
this.key = key;
this.value = value;
}
@Override
public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars envVars) {
if (envVars != null && key != null && value != null) {
envVars.put(key, value);
}
}
public String getDisplayName() {
return "VariableInjectionAction";
}
public String getIconFileName() {
return null;
}
public String getUrlName() {
return null;