Skip to content

Commit

Permalink
JENKINS-56133: Add build url as default annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLud committed Feb 19, 2019
1 parent 41545f6 commit 8ba06a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import hudson.slaves.Cloud;
import jenkins.model.Jenkins;
import org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate;
import org.csanchez.jenkins.plugins.kubernetes.PodAnnotation;
import org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils;

public class PodTemplateStepExecution extends AbstractStepExecutionImpl {
Expand Down Expand Up @@ -95,6 +96,9 @@ public boolean start() throws Exception {
newTemplate.setNodeUsageMode(step.getNodeUsageMode());
newTemplate.setServiceAccount(step.getServiceAccount());
newTemplate.setAnnotations(step.getAnnotations());
if(run!=null) {
newTemplate.getAnnotations().add(new PodAnnotation("buildUrl", ((KubernetesCloud)cloud).getJenkinsUrlOrDie()+run.getUrl()));
}
newTemplate.setImagePullSecrets(
step.getImagePullSecrets().stream().map(x -> new PodImagePullSecret(x)).collect(toList()));
newTemplate.setYaml(step.getYaml());
Expand Down Expand Up @@ -126,7 +130,7 @@ public boolean start() throws Exception {

/**
* Check if the current Job is permitted to use the cloud.
*
*
* @param run
* @param kubernetesCloud
* @throws AbortException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static Map<String, String> getLabels(KubernetesCloud cloud, Object o, Tes

/**
* Delete pods with matching labels
*
*
* @param client
* @param labels
* @param wait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.PodListBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.csanchez.jenkins.plugins.kubernetes.PodAnnotation;

/**
* @author Carlos Sanchez
Expand All @@ -77,7 +78,6 @@ public void runInPod() throws Exception {

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(loadPipelineScript(name.getMethodName() + ".groovy"), true));

logs.capture(1000);
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
Expand Down Expand Up @@ -111,6 +111,18 @@ public void runInPod() throws Exception {

assertThat(templates, hasSize(1));
PodTemplate template = templates.get(0);
List<PodAnnotation> annotations = template.getAnnotations();
assertNotNull(annotations);
boolean foundBuildUrl=false;
for(PodAnnotation pd : annotations)
{
if(pd.getKey().equals("buildUrl"))
{
assertTrue(pd.getValue().contains(p.getUrl()));
foundBuildUrl=true;
}
}
assertTrue(foundBuildUrl);
assertEquals(Integer.MAX_VALUE, template.getInstanceCap());
assertThat(template.getLabelsMap(), hasEntry("jenkins/" + name.getMethodName(), "true"));

Expand Down

0 comments on commit 8ba06a5

Please sign in to comment.