diff --git a/pom.xml b/pom.xml
index d5322bb..faaee0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,9 @@
1.19.6
1.5.5-11
+
1756.v2b_7eea_874392
+ 1.87
@@ -181,6 +183,12 @@
${configuration-as-code.version}
test
+
+ org.jenkins-ci.plugins
+ job-dsl
+ ${jobdsl.version}
+ test
+
diff --git a/src/main/java/jenkins/plugins/jobcacher/CacheWrapper.java b/src/main/java/jenkins/plugins/jobcacher/CacheWrapper.java
index c809b55..604b244 100644
--- a/src/main/java/jenkins/plugins/jobcacher/CacheWrapper.java
+++ b/src/main/java/jenkins/plugins/jobcacher/CacheWrapper.java
@@ -38,6 +38,8 @@
import jenkins.plugins.itemstorage.GlobalItemStorage;
import jenkins.plugins.itemstorage.ItemStorage;
import jenkins.tasks.SimpleBuildWrapper;
+
+import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
@@ -92,6 +94,11 @@ public void setSkipSave(boolean skipSave) {
this.skipSave = skipSave;
}
+ @SuppressWarnings("unused")
+ public boolean getSkipRestore() {
+ return skipRestore;
+ }
+
@SuppressWarnings("unused")
public void setSkipRestore(boolean skipRestore) {
this.skipRestore = skipRestore;
@@ -133,6 +140,7 @@ private static List wrapList(List list, Function, List> lis
}
@Extension
+ @Symbol("jobcacher")
public static final class DescriptorImpl extends BuildWrapperDescriptor {
@NonNull
diff --git a/src/test/java/jenkins/plugins/itemstorage/DataMigrationTest.java b/src/test/java/jenkins/plugins/itemstorage/DataMigrationTest.java
new file mode 100644
index 0000000..9e1a8ef
--- /dev/null
+++ b/src/test/java/jenkins/plugins/itemstorage/DataMigrationTest.java
@@ -0,0 +1,57 @@
+package jenkins.plugins.itemstorage;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.recipes.LocalData;
+
+import jenkins.plugins.itemstorage.local.LocalItemStorage;
+import jenkins.plugins.itemstorage.s3.NonAWSS3ItemStorage;
+import jenkins.plugins.itemstorage.s3.S3ItemStorage;
+
+public class DataMigrationTest {
+
+ @Rule
+ public JenkinsRule jenkins = new JenkinsRule();
+
+ @Test
+ @LocalData
+ public void shouldMigrateLocalData() {
+ ItemStorage> storage = GlobalItemStorage.get().getStorage();
+ assertThat(storage, is(notNullValue()));
+ LocalItemStorage localItemStorage = (LocalItemStorage) storage;
+ assertThat(localItemStorage.getRoot(), is("jobcaches"));
+ }
+
+ @Test
+ @LocalData
+ public void shouldMigrateAwsData() {
+ ItemStorage> storage = GlobalItemStorage.get().getStorage();
+ assertThat(storage, is(notNullValue()));
+ S3ItemStorage s3ItemStorage = (S3ItemStorage) storage;
+ assertThat(s3ItemStorage.getBucketName(), is("bucket1"));
+ assertThat(s3ItemStorage.getRegion(), is("us-gov-west-1"));
+ assertThat(s3ItemStorage.getCredentialsId(), is("s3"));
+ assertThat(s3ItemStorage.getPrefix(), is("the-prefix/"));
+ }
+
+ @Test
+ @LocalData
+ public void shouldMigrateNonAwsData() {
+ ItemStorage> storage = GlobalItemStorage.get().getStorage();
+ assertThat(storage, is(notNullValue()));
+ NonAWSS3ItemStorage s3ItemStorage = (NonAWSS3ItemStorage) storage;
+ assertThat(s3ItemStorage.getBucketName(), is("bucket1"));
+ assertThat(s3ItemStorage.getRegion(), is("eu-central-2"));
+ assertThat(s3ItemStorage.getCredentialsId(), is("s3"));
+ assertThat(s3ItemStorage.getPrefix(), is("the-prefix/"));
+ assertThat(s3ItemStorage.getEndpoint(), is("http://localhost:9000"));
+ assertThat(s3ItemStorage.getParallelDownloads(), is(true));
+ assertThat(s3ItemStorage.getPathStyleAccess(), is(true));
+ }
+
+}
diff --git a/src/test/java/jenkins/plugins/jobdsl/JobDslTest.java b/src/test/java/jenkins/plugins/jobdsl/JobDslTest.java
new file mode 100644
index 0000000..753bb16
--- /dev/null
+++ b/src/test/java/jenkins/plugins/jobdsl/JobDslTest.java
@@ -0,0 +1,57 @@
+package jenkins.plugins.jobdsl;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.hudson.test.Issue;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import hudson.model.FreeStyleProject;
+import javaposse.jobdsl.plugin.ExecuteDslScripts;
+import javaposse.jobdsl.plugin.LookupStrategy;
+import javaposse.jobdsl.plugin.RemovedJobAction;
+import javaposse.jobdsl.plugin.RemovedViewAction;
+import jenkins.plugins.jobcacher.CacheWrapper;
+
+public class JobDslTest {
+
+ public static final String ANSIBLE_DSL_GROOVY_PLAYBOOK = "jobdsl/playbook.groovy";
+
+ @Rule
+ public JenkinsRule jenkins = new JenkinsRule();
+
+ @Test
+ @Issue("https://github.com/jenkinsci/jobcacher-plugin/issues/271")
+ @Ignore
+ public void shouldCreateFreestyleJob() throws Exception {
+ runJobDsl("/jobdsl/freestyle.groovy", jenkins);
+ CacheWrapper step = jenkins.jenkins.getItemByFullName("freestyle", FreeStyleProject.class).getBuildWrappersList().get(CacheWrapper.class);
+ assertNotNull(step);
+ assertThat(step.getCaches(), hasSize(2));
+ assertThat(step.getSkipSave(), is(true));
+ assertThat(step.getSkipRestore(), is(false));
+ assertThat(step.getMaxCacheSize(), is(1024L));
+ assertThat(step.getDefaultBranch(), is("main"));
+ }
+
+ private void runJobDsl(String script, JenkinsRule rule) throws Exception {
+ FreeStyleProject job = rule.createFreeStyleProject();
+ String scriptText = IOUtils.toString(JobDslTest.class.getResourceAsStream(script), StandardCharsets.UTF_8);
+ ExecuteDslScripts builder = new ExecuteDslScripts();
+ builder.setScriptText(scriptText);
+ builder.setRemovedJobAction(RemovedJobAction.DELETE);
+ builder.setRemovedViewAction(RemovedViewAction.DELETE);
+ builder.setLookupStrategy(LookupStrategy.JENKINS_ROOT);
+ job.getBuildersList().add(builder);
+ rule.buildAndAssertSuccess(job);
+ }
+
+}
diff --git a/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
new file mode 100644
index 0000000..5881f62
--- /dev/null
+++ b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
@@ -0,0 +1,9 @@
+
+
+
+ s3
+ bucket1
+ the-prefix/
+ us-gov-west-1
+
+
\ No newline at end of file
diff --git a/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateLocalData/jenkins.plugins.itemstorage.GlobalItemStorage.xml b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateLocalData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
new file mode 100644
index 0000000..e74f17b
--- /dev/null
+++ b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateLocalData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
@@ -0,0 +1,6 @@
+
+
+
+ jobcaches
+
+
diff --git a/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateNonAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateNonAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
new file mode 100644
index 0000000..d1c624c
--- /dev/null
+++ b/src/test/resources/jenkins/plugins/itemstorage/DataMigrationTest/shouldMigrateNonAwsData/jenkins.plugins.itemstorage.GlobalItemStorage.xml
@@ -0,0 +1,12 @@
+
+
+
+ bucket1
+ the-prefix/
+ http://localhost:9000
+ eu-central-2
+ true
+ true
+ s3
+
+
\ No newline at end of file
diff --git a/src/test/resources/jobdsl/freestyle.groovy b/src/test/resources/jobdsl/freestyle.groovy
new file mode 100644
index 0000000..f111549
--- /dev/null
+++ b/src/test/resources/jobdsl/freestyle.groovy
@@ -0,0 +1,25 @@
+freeStyleJob('freestyle') {
+ wrappers {
+ jobcacher {
+ caches {
+ arbitraryFileCache {
+ path('node_modules')
+ includes('**/*')
+ excludes(null)
+ }
+ arbitraryFileCache {
+ path('.m2/repository')
+ includes('**/*')
+ excludes(null)
+ }
+ }
+ skipRestore(false)
+ skipSave(true)
+ defaultBranch('main')
+ maxCacheSize(1024L)
+ }
+ }
+ steps {
+ shell('ls -lah')
+ }
+}