-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make dep on matrix-project
optional
#234
Merged
+77
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,10 +286,14 @@ | |
|
||
// get all CopyArtifacts configured to AbstractProject. This works both for Project and MatrixProject. | ||
private static List<CopyArtifact> getCopyArtifactsInProject(AbstractProject<?,?> project) { | ||
DescribableList<Builder,Descriptor<Builder>> list = | ||
project instanceof Project ? ((Project<?,?>)project).getBuildersList() | ||
: (project instanceof MatrixProject ? | ||
((MatrixProject)project).getBuildersList() : null); | ||
DescribableList<Builder,Descriptor<Builder>> list; | ||
if (project instanceof Project) { | ||
list = ((Project<?,?>)project).getBuildersList(); | ||
} else if (Jenkins.get().getPlugin("matrix-project") != null && project instanceof MatrixProject) { | ||
list = ((MatrixProject)project).getBuildersList(); | ||
} else { | ||
list = null; | ||
} | ||
if (list == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
@@ -543,7 +547,7 @@ | |
if (!ok) { | ||
throw new AbortException(Messages.CopyArtifact_FailedToCopy(expandedProject, expandedFilter)); | ||
} | ||
} else if (src instanceof MatrixBuild) { | ||
} else if (jenkins.getPlugin("matrix-project") != null && src instanceof MatrixBuild) { | ||
Comment on lines
-546
to
+550
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compare #14 (amending 4fd5c3e). Without this, the new test fails:
|
||
boolean ok = false; | ||
// Copy artifacts from all configurations of this matrix build | ||
// Use MatrixBuild.getExactRuns if available | ||
|
@@ -854,10 +858,10 @@ | |
if (item != null) { | ||
if (jenkins.getPlugin("maven-plugin") != null && item instanceof MavenModuleSet) { | ||
result = FormValidation.warning(Messages.CopyArtifact_MavenProject()); | ||
} else if (jenkins.getPlugin("matrix-project") != null && item instanceof MatrixProject) { | ||
result = FormValidation.warning(Messages.CopyArtifact_MatrixProject()); | ||
} else { | ||
result = (item instanceof MatrixProject) | ||
? FormValidation.warning(Messages.CopyArtifact_MatrixProject()) | ||
: FormValidation.ok(); | ||
result = FormValidation.ok(); | ||
} | ||
} else if (value.indexOf('$') >= 0) { | ||
result = FormValidation.warning(Messages.CopyArtifact_ParameterizedName()); | ||
|
58 changes: 58 additions & 0 deletions
58
src/test/java/hudson/plugins/copyartifact/OptionalDepsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2024 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package hudson.plugins.copyartifact; | ||
|
||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
import org.jvnet.hudson.test.TailLog; | ||
|
||
/** Verifies that basic functionality works without optional plugin dependencies. */ | ||
public final class OptionalDepsTest { | ||
|
||
@Rule public RealJenkinsRule r = new RealJenkinsRule().omitPlugins("maven-plugin", "matrix-project"); | ||
|
||
@Test public void usePipeline() throws Throwable { | ||
r.then(OptionalDepsTest::_usePipeline); | ||
} | ||
|
||
/** Adapted from {@link CopyArtifactWorkflowTest#testLastCompletedBuildSelector}. */ | ||
private static void _usePipeline(JenkinsRule r) throws Throwable { | ||
var upstream = r.createProject(WorkflowJob.class, "upstream"); | ||
upstream.setDefinition(new CpsFlowDefinition("node {writeFile text: 'upstream content', file: 'x.txt'; archiveArtifacts 'x.txt'}", true)); | ||
try (var tail = new TailLog(r, "upstream", 1)) { | ||
r.buildAndAssertSuccess(upstream); | ||
} | ||
var downstream = r.createProject(WorkflowJob.class, "downstream"); | ||
downstream.setDefinition(new CpsFlowDefinition("node {copyArtifacts(projectName: 'upstream', selector: lastCompleted()); echo readFile('x.txt')}", true)); | ||
try (var tail = new TailLog(r, "downstream", 1)) { | ||
r.assertLogContains("upstream content", r.buildAndAssertSuccess(downstream)); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jenkinsci/jenkins#9478