Hello, utilizing SimpleBuildWrapper is it possible to update EnvVars post 
setup but before disposal? Use case is to update tokens provided from SAML 
when session is about to expire. Contents of the block would be tools like 
AWS CLI that can pull keys/tokens from EnvVar.

I have something that quasi works by using a custom version of 
SimpleBuildWrapper to allow updates to an existing env key:
    public static final class Context {
        private Disposer disposer;
        private final Map<String,String> env = new HashMap<String,String>();
        public @Nonnull Map<String,String> getEnv() {
            return env;
        }

        public void env(String key, String value) {
            //if (env.containsKey(key)) {
            //    throw new IllegalStateException("just one binding for " + 
key);
            //}
            env.put(key, value);
        }
    ...

Then from inside the implementation's setup function:
            Runnable runnable = new Runnable() {
                public void run() {
                    updateENV(context);
                }
            };

            thread = new Thread(runnable);
            thread.start();
            context.setDisposer(new DisposeEnvironment(thread));

Teardown:
    private static class DisposeEnvironment extends Disposer {
        private static final long serialVersionUID = 1;
        private final Thread thread;

        DisposeEnvironment(Thread thread) { this.thread = thread; }

        @Override
        public void tearDown(
                Run<?, ?> build,
                FilePath workspace,
                Launcher launcher,
                TaskListener listener
        ) throws IOException, InterruptedException {
            thread.interrupt();
        }
    }


This only works for build step initialization inside the wrapper's block. 
Once a build step is running it appears it only retains whatever state 
Context was in during initialization. The next build step in a sequence of 
steps will then get the new Context state and so on. Preferably I'd like to 
update Context of a build step while it's still running as well. Is there a 
method of doing this?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/2d0bd969-e841-42fe-90a9-300d7d21ec60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to