Skip to content
Permalink
Browse files

JENKINS-41677 Expose display URLs in environment variables (#8)

  • Loading branch information...
i386 committed Feb 2, 2017
1 parent 3b5e95f commit 6804a3b8e86d265ed514fc230cb386c7d7468c05
@@ -0,0 +1,26 @@
package org.jenkinsci.plugins.displayurlapi;

import hudson.EnvVars;
import hudson.Extension;
import hudson.model.EnvironmentContributor;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.TaskListener;

import javax.annotation.Nonnull;
import java.io.IOException;

@Extension
public class EnvironmentContributorImpl extends EnvironmentContributor {
@Override
public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
DisplayURLProvider urlProvider = DisplayURLProvider.get();
envs.put("RUN_DISPLAY_URL", urlProvider.getRunURL(r));
envs.put("RUN_CHANGES_DISPLAY_URL", urlProvider.getChangesURL(r));
}

@Override
public void buildEnvironmentFor(@Nonnull Job j, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
envs.put("JOB_DISPLAY_URL", DisplayURLProvider.get().getJobURL(j));
}
}
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.displayurlapi;

import hudson.EnvVars;
import hudson.model.FreeStyleProject;
import hudson.model.Run;
import hudson.tasks.test.AbstractTestResultAction;
@@ -30,6 +31,11 @@ public void urls() throws Exception {
assertEquals(root + "job/my%20folder/job/my%20job/1/display/redirect", DisplayURLProvider.get().getRunURL(run));
assertEquals(root + "job/my%20folder/job/my%20job/display/redirect", DisplayURLProvider.get().getJobURL(project));
assertEquals(root + "job/my%20folder/job/my%20job/1/display/redirect?page=changes", DisplayURLProvider.get().getChangesURL(run));

EnvVars environment = run.getEnvironment();
assertEquals(DisplayURLProvider.get().getRunURL(run), environment.get("RUN_DISPLAY_URL"));
assertEquals(DisplayURLProvider.get().getChangesURL(run), environment.get("RUN_CHANGES_DISPLAY_URL"));
assertEquals(DisplayURLProvider.get().getJobURL(project), environment.get("JOB_DISPLAY_URL"));
}

@Test

0 comments on commit 6804a3b

Please sign in to comment.
You can’t perform that action at this time.