Skip to content

Commit

Permalink
Fix failure with configuration-as-code plugin when upgrading (#JENKIN…
Browse files Browse the repository at this point in the history
…S-73843) (#495)
  • Loading branch information
alextu committed Oct 8, 2024
1 parent 8a567ac commit febb635
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ dependencies {
testImplementation("org.jenkins-ci.main:jenkins-test-harness:2225.v04fa_3929c9b_5")
testImplementation("org.jenkins-ci.main:jenkins-test-harness-tools:2.2")
testImplementation("io.jenkins:configuration-as-code:1.4")
testImplementation("io.jenkins.configuration-as-code:test-harness:1.4")
testImplementation("org.jenkins-ci.plugins:timestamper")
testImplementation("org.jenkins-ci.plugins:pipeline-stage-step")
testImplementation("org.jenkins-ci.plugins:pipeline-maven:3.10.0")
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/hudson/plugins/gradle/injection/InjectionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public class InjectionConfig extends GlobalConfiguration {
// Legacy property that is not used anymore
private transient String injectionVcsRepositoryPatterns;
private VcsRepositoryFilter parsedVcsRepositoryFilter = VcsRepositoryFilter.EMPTY;
// Legacy properties, kept for reading old configurations
private transient boolean injectMavenExtension;
private transient boolean injectCcudExtension;

public InjectionConfig() {
load();
Expand Down Expand Up @@ -367,6 +370,24 @@ public void setCheckForBuildAgentErrors(boolean checkForBuildAgentErrors) {
this.checkForBuildAgentErrors = checkForBuildAgentErrors;
}

public boolean isInjectCcudExtension() {
return injectCcudExtension;
}

@DataBoundSetter
public void setInjectCcudExtension(boolean injectCcudExtension) {
this.injectCcudExtension = injectCcudExtension;
}

public boolean isInjectMavenExtension() {
return injectMavenExtension;
}

@DataBoundSetter
public void setInjectMavenExtension(boolean injectMavenExtension) {
this.injectMavenExtension = injectMavenExtension;
}

/**
* Required to display filter in the UI.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package hudson.plugins.gradle.injection


import hudson.plugins.gradle.AbstractIntegrationTest
import io.jenkins.plugins.casc.misc.ConfiguredWithCode
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule
import org.junit.Rule
import org.junit.rules.RuleChain
import spock.lang.Subject
import spock.lang.Unroll

@Unroll
@Subject(InjectionConfig.class)
class InjectionConfigWithCasCTest extends AbstractIntegrationTest {
@Rule
public final RuleChain rules = RuleChain.outerRule(noSpaceInTmpDirs).around(new JenkinsConfiguredWithCodeRule())

@ConfiguredWithCode("injection-config.yml")
def 'current configuration is readable with JCasC'() {
expect:
with(InjectionConfig.get()) {
it.allowUntrusted == true
it.ccudExtensionCustomCoordinates == "mycustom-ccud:ext"
it.ccudExtensionVersion == "2.0.1"
it.ccudPluginVersion == "2.0.2"
it.checkForBuildAgentErrors == true
it.enabled == true
it.enforceUrl == true
it.gradleCaptureTaskInputFiles == true
it.gradleInjectionDisabledNodes*.label == ["non-gradle-node"]
it.gradleInjectionEnabledNodes*.label == ["gradle-node"]
it.gradlePluginRepositoryUrl == "https://plugins.gradle.org"
it.gradlePluginVersion == "3.18.1"
it.injectMavenExtension == true
it.injectCcudExtension == true
it.mavenCaptureGoalInputFiles == true
it.mavenExtensionCustomCoordinates == "mycustom:ext"
it.mavenExtensionRepositoryUrl == "https://repo1.maven.org/maven2"
it.mavenExtensionVersion == "1.22.1"
it.mavenInjectionDisabledNodes*.label == ["non-maven-node"]
it.mavenInjectionEnabledNodes*.label == ["maven-node"]
it.server == "http://localhost:5086"
it.shortLivedTokenExpiry == 24
it.vcsRepositoryFilter == "+:myrepo"
}
}
}
30 changes: 30 additions & 0 deletions src/test/resources/injection-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
jenkins:
unclassified:
injectionConfig:
allowUntrusted: true
ccudExtensionCustomCoordinates: "mycustom-ccud:ext"
ccudExtensionVersion: "2.0.1"
ccudPluginVersion: "2.0.2"
checkForBuildAgentErrors: true
enabled: true
enforceUrl: true
gradleCaptureTaskInputFiles: true
gradleInjectionDisabledNodes:
- label: "non-gradle-node"
gradleInjectionEnabledNodes:
- label: "gradle-node"
gradlePluginRepositoryUrl: "https://plugins.gradle.org"
gradlePluginVersion: "3.18.1"
injectMavenExtension: true
injectCcudExtension: true
mavenCaptureGoalInputFiles: true
mavenExtensionCustomCoordinates: "mycustom:ext"
mavenExtensionRepositoryUrl: "https://repo1.maven.org/maven2"
mavenExtensionVersion: "1.22.1"
mavenInjectionDisabledNodes:
- label: "non-maven-node"
mavenInjectionEnabledNodes:
- label: "maven-node"
server: "http://localhost:5086"
shortLivedTokenExpiry: 24
vcsRepositoryFilter: "+:myrepo"

0 comments on commit febb635

Please sign in to comment.