25
25
package org .jenkinsci .plugins .workflow .multibranch ;
26
26
27
27
import edu .umd .cs .findbugs .annotations .NonNull ;
28
+ import hudson .AbortException ;
28
29
import hudson .Extension ;
29
30
import hudson .Functions ;
30
- import hudson .MarkupText ;
31
- import hudson .console .ConsoleAnnotationDescriptor ;
32
- import hudson .console .ConsoleAnnotator ;
33
- import hudson .console .ConsoleNote ;
34
31
import hudson .model .Action ;
35
32
import hudson .model .Descriptor ;
36
33
import hudson .model .DescriptorVisibilityFilter ;
46
43
import jenkins .scm .api .SCMRevision ;
47
44
import jenkins .scm .api .SCMRevisionAction ;
48
45
import jenkins .scm .api .SCMSource ;
46
+ import jenkins .util .SystemProperties ;
49
47
import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
50
48
import org .jenkinsci .plugins .workflow .cps .CpsScmFlowDefinition ;
51
49
import org .jenkinsci .plugins .workflow .flow .FlowDefinition ;
61
59
class SCMBinder extends FlowDefinition {
62
60
63
61
/** Kill switch for JENKINS-33273 in case of problems. */
64
- static /* not final */ boolean USE_HEAVYWEIGHT_CHECKOUT = Boolean .getBoolean (SCMBinder .class .getName () + ".USE_HEAVYWEIGHT_CHECKOUT" ); // TODO 2.4+ use SystemProperties
62
+ static /* not final */ boolean USE_HEAVYWEIGHT_CHECKOUT = SystemProperties .getBoolean (SCMBinder .class .getName () + ".USE_HEAVYWEIGHT_CHECKOUT" );
63
+
64
+ /** Kill switch for making this as strict as {@link ReadTrustedStep} about untrusted modifications. */
65
+ static /* not final */ boolean IGNORE_UNTRUSTED_EDITS = SystemProperties .getBoolean (SCMBinder .class .getName () + ".IGNORE_UNTRUSTED_EDITS" );
66
+
65
67
private String scriptPath = WorkflowBranchProjectFactory .SCRIPT ;
66
68
67
69
public Object readResolve () {
@@ -111,10 +113,10 @@ public SCMBinder(String scriptPath) {
111
113
listener .error ("Could not do lightweight checkout, falling back to heavyweight" ).println (Functions .printThrowable (x ).trim ());
112
114
}
113
115
if (script != null ) {
114
- if (!rev .equals (tip )) {
115
- // Print a warning in builds where an untrusted contributor has tried to edit Jenkinsfile.
116
- // If we fail to check this (e.g., due to heavyweight checkout), a warning will still be printed to the log
117
- // by the SCM, but that is less apparent .
116
+ if (!IGNORE_UNTRUSTED_EDITS && ! rev .equals (tip )) {
117
+ // Make a best effort to abort builds where an untrusted contributor has tried to edit Jenkinsfile.
118
+ // If we fail to check this (e.g., due to heavyweight checkout), a warning will be printed to the log
119
+ // and the build will continue with the trusted variant, which is safe but confusing .
118
120
SCMFileSystem tipFS = SCMFileSystem .of (scmSource , head , tip );
119
121
if (tipFS != null ) {
120
122
String tipScript = null ;
@@ -124,9 +126,7 @@ public SCMBinder(String scriptPath) {
124
126
listener .error ("Could not compare lightweight checkout of trusted revision" ).println (Functions .printThrowable (x ).trim ());
125
127
}
126
128
if (tipScript != null && !script .equals (tipScript )) {
127
- listener .annotate (new WarningNote ());
128
- listener .getLogger ().println (Messages .ReadTrustedStep__has_been_modified_in_an_untrusted_revis (scriptPath ));
129
- // TODO JENKINS-45970 consider aborting instead, at least optionally
129
+ throw new AbortException (Messages .ReadTrustedStep__has_been_modified_in_an_untrusted_revis (scriptPath ));
130
130
}
131
131
}
132
132
}
@@ -165,22 +165,4 @@ public SCMBinder(String scriptPath) {
165
165
166
166
}
167
167
168
- // TODO seems there is no general-purpose ConsoleNote which simply wraps markup in specified HTML
169
- @ SuppressWarnings ("rawtypes" )
170
- public static class WarningNote extends ConsoleNote {
171
-
172
- @ Override public ConsoleAnnotator annotate (Object context , MarkupText text , int charPos ) {
173
- text .addMarkup (0 , text .length (), "<span class='warning-inline'>" , "</span>" );
174
- return null ;
175
- }
176
-
177
- @ Extension public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {
178
- @ NonNull
179
- @ Override public String getDisplayName () {
180
- return "Multibranch warnings" ;
181
- }
182
- }
183
-
184
- }
185
-
186
168
}
0 commit comments