Skip to content

Commit 211bd14

Browse files
committed
Merge branch 'master' into logs-JENKINS-38381
Also using jitpack and linking to jenkinsci/maven-hpi-plugin#46 & jenkinsci/workflow-api-plugin#17 & jenkinsci/workflow-support-plugin#15.
2 parents 89559d5 + 139ac7e commit 211bd14

File tree

9 files changed

+321
-46
lines changed

9 files changed

+321
-46
lines changed

pom.xml

+19-26
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
<parent>
2929
<groupId>org.jenkins-ci.plugins</groupId>
3030
<artifactId>plugin</artifactId>
31-
<version>2.16</version>
32-
<relativePath/>
31+
<version>2.19</version>
32+
<relativePath />
3333
</parent>
3434
<groupId>org.jenkins-ci.plugins.workflow</groupId>
3535
<artifactId>workflow-job</artifactId>
36-
<version>2.8-SNAPSHOT</version>
36+
<version>2.10-SNAPSHOT</version>
3737
<packaging>hpi</packaging>
3838
<name>Pipeline: Job</name>
3939
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Job+Plugin</url>
@@ -54,6 +54,10 @@
5454
<id>repo.jenkins-ci.org</id>
5555
<url>https://repo.jenkins-ci.org/public/</url>
5656
</repository>
57+
<repository> <!-- TODO as below -->
58+
<id>jitpack.io</id>
59+
<url>https://jitpack.io</url>
60+
</repository>
5761
</repositories>
5862
<pluginRepositories>
5963
<pluginRepository>
@@ -64,6 +68,9 @@
6468
<properties>
6569
<jenkins.version>1.642.3</jenkins.version>
6670
<jenkins-test-harness.version>2.17</jenkins-test-harness.version>
71+
<no-test-jar>false</no-test-jar>
72+
<hpi-plugin.version>1.121-20161207.210916-1</hpi-plugin.version> <!-- TODO pending https://github.com/jenkinsci/maven-hpi-plugin/pull/46 -->
73+
<enforcer.fail>false</enforcer.fail> <!-- TODO ditto -->
6774
</properties>
6875
<dependencies>
6976
<dependency>
@@ -72,14 +79,14 @@
7279
<version>2.4</version>
7380
</dependency>
7481
<dependency>
75-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
76-
<artifactId>workflow-api</artifactId>
77-
<version>2.5-SNAPSHOT</version>
82+
<groupId>com.github.jglick</groupId> <!-- TODO pending https://github.com/jenkinsci/workflow-api-plugin/pull/17 -->
83+
<artifactId>workflow-api-plugin</artifactId>
84+
<version>99f1c51</version>
7885
</dependency>
7986
<dependency>
80-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
81-
<artifactId>workflow-support</artifactId>
82-
<version>2.9-SNAPSHOT</version>
87+
<groupId>com.github.jglick</groupId> <!-- TODO pending https://github.com/jenkinsci/workflow-support-plugin/pull/15 -->
88+
<artifactId>workflow-support-plugin</artifactId>
89+
<version>cf6f11f</version>
8390
</dependency>
8491
<dependency>
8592
<groupId>org.jenkins-ci.plugins</groupId>
@@ -99,9 +106,9 @@
99106
<scope>test</scope>
100107
</dependency>
101108
<dependency>
102-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
103-
<artifactId>workflow-support</artifactId>
104-
<version>2.9-SNAPSHOT</version>
109+
<groupId>com.github.jglick</groupId> <!-- TODO pending https://github.com/jenkinsci/workflow-support-plugin/pull/15 -->
110+
<artifactId>workflow-support-plugin</artifactId>
111+
<version>cf6f11f</version>
105112
<classifier>tests</classifier>
106113
<scope>test</scope>
107114
</dependency>
@@ -112,18 +119,4 @@
112119
<scope>test</scope>
113120
</dependency>
114121
</dependencies>
115-
<build>
116-
<plugins>
117-
<plugin>
118-
<artifactId>maven-jar-plugin</artifactId>
119-
<executions>
120-
<execution>
121-
<goals>
122-
<goal>test-jar</goal>
123-
</goals>
124-
</execution>
125-
</executions>
126-
</plugin>
127-
</plugins>
128-
</build>
129122
</project>

src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty;
9797
import org.kohsuke.accmod.Restricted;
9898
import org.kohsuke.accmod.restrictions.DoNotUse;
99+
import org.kohsuke.accmod.restrictions.NoExternalUse;
99100
import org.kohsuke.stapler.QueryParameter;
100101
import org.kohsuke.stapler.StaplerRequest;
101102
import org.kohsuke.stapler.StaplerResponse;
@@ -445,6 +446,11 @@ public PipelineTriggersJobProperty getTriggersJobProperty() {
445446
return triggerProp;
446447
}
447448

449+
@Restricted(NoExternalUse.class)
450+
public void addTriggersJobPropertyWithoutStart(PipelineTriggersJobProperty prop) throws IOException {
451+
super.addProperty(prop);
452+
}
453+
448454
public void setTriggers(List<Trigger<?>> inputTriggers) throws IOException {
449455
triggers = null;
450456
BulkChange bc = new BulkChange(this);

src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

+45-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import hudson.model.listeners.RunListener;
5050
import hudson.model.listeners.SCMListener;
5151
import hudson.scm.ChangeLogSet;
52+
import hudson.scm.RepositoryBrowser;
5253
import hudson.scm.SCM;
5354
import hudson.scm.SCMRevisionState;
5455
import hudson.security.ACL;
@@ -71,6 +72,7 @@
7172
import java.util.HashMap;
7273
import java.util.LinkedList;
7374
import java.util.List;
75+
import java.util.Locale;
7476
import java.util.Map;
7577
import java.util.concurrent.Future;
7678
import java.util.concurrent.TimeUnit;
@@ -104,6 +106,7 @@
104106
import org.jenkinsci.plugins.workflow.support.concurrent.Futures;
105107
import org.jenkinsci.plugins.workflow.support.steps.input.POSTHyperlinkNote;
106108
import org.kohsuke.accmod.Restricted;
109+
import org.kohsuke.accmod.restrictions.DoNotUse;
107110
import org.kohsuke.accmod.restrictions.NoExternalUse;
108111
import org.kohsuke.stapler.HttpResponse;
109112
import org.kohsuke.stapler.HttpResponses;
@@ -116,6 +119,14 @@ public final class WorkflowRun extends Run<WorkflowJob,WorkflowRun> implements F
116119

117120
private static final Logger LOGGER = Logger.getLogger(WorkflowRun.class.getName());
118121

122+
private enum StopState {
123+
TERM, KILL;
124+
125+
public String url() {
126+
return this.name().toLowerCase(Locale.ENGLISH);
127+
}
128+
}
129+
119130
/** null until started, or after serious failures or hard kill */
120131
private @CheckForNull FlowExecution execution;
121132

@@ -131,6 +142,10 @@ public final class WorkflowRun extends Run<WorkflowJob,WorkflowRun> implements F
131142
};
132143
private transient BuildListener listener;
133144

145+
private transient boolean allowTerm;
146+
147+
private transient boolean allowKill;
148+
134149
/**
135150
* Flag for whether or not the build has completed somehow.
136151
* Non-null soon after the build starts or is reloaded from disk.
@@ -245,7 +260,7 @@ private AsynchronousExecution sleep() {
245260
LOGGER.log(Level.WARNING, null, x);
246261
}
247262
executor.recordCauseOfInterruption(WorkflowRun.this, listener);
248-
printLater("term", "Click here to forcibly terminate running steps");
263+
printLater(StopState.TERM, "Click here to forcibly terminate running steps");
249264
}
250265
});
251266
}
@@ -258,13 +273,21 @@ private AsynchronousExecution sleep() {
258273
};
259274
}
260275

261-
private void printLater(final String url, final String message) {
276+
private void printLater(final StopState state, final String message) {
262277
Timer.get().schedule(new Runnable() {
263278
@Override public void run() {
264279
if (!isInProgress()) {
265280
return;
266281
}
267-
listener.getLogger().println(POSTHyperlinkNote.encodeTo("/" + getUrl() + url, message));
282+
switch (state) {
283+
case TERM:
284+
allowTerm = true;
285+
break;
286+
case KILL:
287+
allowKill = true;
288+
break;
289+
}
290+
listener.getLogger().println(POSTHyperlinkNote.encodeTo("/" + getUrl() + state.url(), message));
268291
}
269292
}, 15, TimeUnit.SECONDS);
270293
}
@@ -294,7 +317,7 @@ public void doTerm() {
294317
}
295318
@Override public void onFailure(Throwable t) {}
296319
});
297-
printLater("kill", "Click here to forcibly kill entire build");
320+
printLater(StopState.KILL, "Click here to forcibly kill entire build");
298321
}
299322

300323
/** Immediately kills the build. */
@@ -327,6 +350,16 @@ public void doKill() {
327350
return env;
328351
}
329352

353+
@Restricted(DoNotUse.class) // Jelly
354+
public boolean hasAllowTerm() {
355+
return isBuilding() && allowTerm;
356+
}
357+
358+
@Restricted(DoNotUse.class) // Jelly
359+
public boolean hasAllowKill() {
360+
return isBuilding() && allowKill;
361+
}
362+
330363
private static final Map<String,WorkflowRun> LOADING_RUNS = new HashMap<>();
331364

332365
private String key() {
@@ -423,7 +456,7 @@ private void finish(@Nonnull Result r, @CheckForNull Throwable t) {
423456
save();
424457
getParent().logRotate();
425458
} catch (Exception x) {
426-
LOGGER.log(Level.WARNING, null, x);
459+
LOGGER.log(Level.WARNING, "failed to save " + this + " or perform log rotation", x);
427460
}
428461
onEndBuilding();
429462
if (completed != null) {
@@ -509,7 +542,7 @@ public synchronized List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSe
509542
if (co.changelogFile != null && co.changelogFile.isFile()) {
510543
try {
511544
ChangeLogSet<? extends ChangeLogSet.Entry> changeLogSet =
512-
co.scm.createChangeLogParser().parse(this, co.scm.getEffectiveBrowser(), co.changelogFile);
545+
co.scm.createChangeLogParser().parse(this, getEffectiveBrowser(co.scm), co.changelogFile);
513546
if (!changeLogSet.isEmptySet()) {
514547
changeSets.add(changeLogSet);
515548
}
@@ -522,6 +555,12 @@ public synchronized List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSe
522555
return changeSets;
523556
}
524557

558+
/** Replacement for {@link SCM#getEffectiveBrowser} to work around JENKINS-35098. TODO 2.7.3+ delete */
559+
private static RepositoryBrowser<?> getEffectiveBrowser(SCM scm) {
560+
RepositoryBrowser<?> b = scm.getBrowser();
561+
return b != null ? b : scm.guessBrowser();
562+
}
563+
525564
@RequirePOST
526565
public synchronized HttpResponse doStop() {
527566
Executor e = getOneOffExecutor();

src/main/java/org/jenkinsci/plugins/workflow/job/properties/PipelineTriggersJobProperty.java

+28-8
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@
4949
import java.util.HashMap;
5050
import java.util.List;
5151
import java.util.Map;
52+
import java.util.logging.Level;
53+
import java.util.logging.Logger;
5254

5355
@SuppressWarnings("rawtypes")
5456
public class PipelineTriggersJobProperty extends JobProperty<WorkflowJob> {
57+
private static final Logger LOGGER = Logger.getLogger(PipelineTriggersJobProperty.class.getName());
58+
5559
private List<Trigger<?>> triggers = new ArrayList<>();
5660

5761
@DataBoundConstructor
@@ -133,26 +137,42 @@ public List<Action> getAllTriggerActions() {
133137
@CheckForNull
134138
@Override
135139
public PipelineTriggersJobProperty reconfigure(@Nonnull StaplerRequest req, @CheckForNull JSONObject form) throws Descriptor.FormException {
136-
DescribableList<Trigger<?>,TriggerDescriptor> trigList = new DescribableList<>(Saveable.NOOP);
140+
DescribableList<Trigger<?>, TriggerDescriptor> trigList = new DescribableList<>(Saveable.NOOP);
137141
try {
138142
JSONObject triggerSection = new JSONObject();
139143
if (form != null) {
140144
triggerSection = form.getJSONObject("triggers");
141145
}
142146
trigList.rebuild(req, triggerSection, Trigger.for_(owner));
143147
} catch (IOException e) {
144-
// TODO: Not sure what form field would make sense here?
145-
throw new Descriptor.FormException(e, null);
148+
throw new Descriptor.FormException(e, "triggers");
146149
}
147150

148-
this.stopTriggers();
151+
PipelineTriggersJobProperty oldProp = owner.getTriggersJobProperty();
152+
153+
try {
154+
owner.removeProperty(this);
155+
PipelineTriggersJobProperty thisProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>(trigList.toList()));
156+
157+
owner.addTriggersJobPropertyWithoutStart(thisProp);
149158

150-
PipelineTriggersJobProperty thisProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>(trigList.toList()));
151-
thisProp.setOwner(owner);
159+
thisProp.startTriggers(true);
160+
return thisProp;
161+
} catch (IOException e) {
162+
LOGGER.log(Level.WARNING, "could not configure triggers", e);
163+
}
152164

153-
thisProp.startTriggers(true);
165+
if (owner.getTriggersJobProperty() == null && oldProp != null) {
166+
try {
167+
owner.addTriggersJobPropertyWithoutStart(oldProp);
168+
oldProp.startTriggers(true);
169+
} catch (IOException e) {
170+
LOGGER.log(Level.WARNING, "could not revert to original configured triggers", e);
171+
throw new Descriptor.FormException("Could not revert to original configured triggers", e, "triggers");
172+
}
173+
}
154174

155-
return thisProp;
175+
return oldProp;
156176
}
157177

158178
@Extension(ordinal = -100)

src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowRun/sidepanel.jelly

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@
4444
</j:choose>
4545
<l:task icon="images/24x24/notepad.png" href="${buildUrl.baseUrl}/configure" title="${h.hasPermission(it,it.UPDATE)?'%Edit Build Information':'%View Build Information'}"/>
4646
<st:include page="delete.jelly"/>
47+
<j:if test="${it.hasAllowTerm()}">
48+
<l:task icon="images/24x24/edit-delete.png"
49+
href="${buildUrl.baseUrl}/term"
50+
title="${%Abort Running Steps}"
51+
contextMenu="false"
52+
post="true"
53+
permission="${it.CANCEL}"
54+
requiresConfirmation="true"
55+
confirmationMessage="${%Really forcibly abort running steps?}"/>
56+
</j:if>
57+
<j:if test="${it.hasAllowKill()}">
58+
<l:task icon="images/24x24/edit-delete.png"
59+
href="${buildUrl.baseUrl}/kill"
60+
title="${%Force Abort of Entire Build}"
61+
contextMenu="false"
62+
post="true"
63+
permission="${it.CANCEL}"
64+
requiresConfirmation="true"
65+
confirmationMessage="${%Really forcibly abort entire build?}"/>
66+
</j:if>
4767
<st:include page="actions.jelly"/>
4868
<t:actions actions="${it.transientActions}"/>
4969
<j:if test="${it.previousBuild!=null}">

0 commit comments

Comments
 (0)