diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..65ad8f5 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @jenkinsci/first-plugin-developers diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..03b4d66 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates + +version: 2 +updates: +- package-ecosystem: maven + directory: / + schedule: + interval: monthly +- package-ecosystem: github-actions + directory: / + schedule: + interval: monthly diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..c877750 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,2 @@ +_extends: .github +tag-template: first-$NEXT_MINOR_VERSION diff --git a/.github/workflows/jenkins-security-scan.yml b/.github/workflows/jenkins-security-scan.yml new file mode 100644 index 0000000..f1995d8 --- /dev/null +++ b/.github/workflows/jenkins-security-scan.yml @@ -0,0 +1,23 @@ +# More information about the Jenkins security scan can be found at the developer docs: https://www.jenkins.io/redirect/jenkins-security-scan/ + +name: Jenkins Security Scan +on: + push: + branches: + - "master" + - "main" + pull_request: + types: [ opened, synchronize, reopened ] + workflow_dispatch: + +permissions: + security-events: write + contents: read + actions: read + +jobs: + security-scan: + uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 + with: + java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. + java-version: 11 # What version of Java to set up for the build. diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..f8e19b4 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,17 @@ +# Automates creation of Release Drafts using Release Drafter +# More Info: https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc + +on: + push: + branches: + - master + - main + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into the default branch + - uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0834364 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +target + +# mvn hpi:run +work + +# IntelliJ IDEA project files +*.iml +*.iws +*.ipr +.idea + +# Eclipse project files +.settings +.classpath +.project diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 0000000..a64ab6f --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + io.jenkins.tools.incrementals + git-changelist-maven-extension + 1.7 + + diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 0000000..2a0299c --- /dev/null +++ b/.mvn/maven.config @@ -0,0 +1,2 @@ +-Pconsume-incrementals +-Pmight-produce-incrementals diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..09032da --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,11 @@ +/* + See the documentation for more options: + https://github.com/jenkins-infra/pipeline-library/ +*/ +buildPlugin( + forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores + useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests + configurations: [ + [platform: 'linux', jdk: 21], + [platform: 'windows', jdk: 17], +]) diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a187bd6 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License + +Copyright 2024 + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4586a84 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# first + +## Introduction + +TODO Describe what your plugin does here + +## Getting started + +TODO Tell users how to configure your plugin here, include screenshots, pipeline examples and +configuration-as-code examples. + +## Issues + +TODO Decide where you're going to host your issues, the default is Jenkins JIRA, but you can also enable GitHub issues, +If you use GitHub issues there's no need for this section; else add the following line: + +Report issues and enhancements in the [Jenkins issue tracker](https://issues.jenkins.io/). + +## Contributing + +TODO review the default [CONTRIBUTING](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md) file and make sure it is appropriate for your plugin, if not then add your own one adapted from the base file + +Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md) + +## LICENSE + +Licensed under MIT, see [LICENSE](LICENSE.md) + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c5a933d --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + + org.jenkins-ci.plugins + plugin + 4.78 + + + + io.jenkins.plugins + first + ${revision}${changelist} + hpi + + TODO Plugin + https://github.com/jenkinsci/${project.artifactId}-plugin + + + MIT License + https://opensource.org/license/mit/ + + + + scm:git:https://github.com/${gitHubRepo} + scm:git:https://github.com/${gitHubRepo} + ${scmTag} + https://github.com/${gitHubRepo} + + + 1.0 + -SNAPSHOT + + 2.414.3 + jenkinsci/${project.artifactId}-plugin + false + + + + + + io.jenkins.tools.bom + bom-2.414.x + 2857.v01a_0144eb_20b_ + pom + import + + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + diff --git a/src/main/java/io/jenkins/plugins/sample/SampleConfiguration.java b/src/main/java/io/jenkins/plugins/sample/SampleConfiguration.java new file mode 100644 index 0000000..d01aaf9 --- /dev/null +++ b/src/main/java/io/jenkins/plugins/sample/SampleConfiguration.java @@ -0,0 +1,50 @@ +package io.jenkins.plugins.sample; + +import hudson.Extension; +import hudson.ExtensionList; +import hudson.util.FormValidation; +import jenkins.model.GlobalConfiguration; +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.DataBoundSetter; +import org.kohsuke.stapler.QueryParameter; + +/** + * Example of Jenkins global configuration. + */ +@Extension +public class SampleConfiguration extends GlobalConfiguration { + + /** @return the singleton instance */ + public static SampleConfiguration get() { + return ExtensionList.lookupSingleton(SampleConfiguration.class); + } + + private String label; + + public SampleConfiguration() { + // When Jenkins is restarted, load any saved configuration from disk. + load(); + } + + /** @return the currently configured label, if any */ + public String getLabel() { + return label; + } + + /** + * Together with {@link #getLabel}, binds to entry in {@code config.jelly}. + * @param label the new value of this field + */ + @DataBoundSetter + public void setLabel(String label) { + this.label = label; + save(); + } + + public FormValidation doCheckLabel(@QueryParameter String value) { + if (StringUtils.isEmpty(value)) { + return FormValidation.warning("Please specify a label."); + } + return FormValidation.ok(); + } +} diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly new file mode 100644 index 0000000..35f37a7 --- /dev/null +++ b/src/main/resources/index.jelly @@ -0,0 +1,4 @@ + +
+ TODO +
diff --git a/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/config.jelly b/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/config.jelly new file mode 100644 index 0000000..c82df16 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/config.jelly @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/help-label.html b/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/help-label.html new file mode 100644 index 0000000..c61a269 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/sample/SampleConfiguration/help-label.html @@ -0,0 +1,3 @@ +
+ Explanation of what the label does. +
diff --git a/src/test/java/io/jenkins/plugins/sample/SampleConfigurationTest.java b/src/test/java/io/jenkins/plugins/sample/SampleConfigurationTest.java new file mode 100644 index 0000000..d6cf932 --- /dev/null +++ b/src/test/java/io/jenkins/plugins/sample/SampleConfigurationTest.java @@ -0,0 +1,45 @@ +package io.jenkins.plugins.sample; + +import static org.junit.Assert.*; + +import org.htmlunit.html.HtmlForm; +import org.htmlunit.html.HtmlTextInput; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsSessionRule; + +public class SampleConfigurationTest { + + @Rule + public JenkinsSessionRule sessions = new JenkinsSessionRule(); + + /** + * Tries to exercise enough code paths to catch common mistakes: + * + */ + @Test + public void uiAndStorage() throws Throwable { + sessions.then(r -> { + assertNull("not set initially", SampleConfiguration.get().getLabel()); + HtmlForm config = r.createWebClient().goTo("configure").getFormByName("config"); + HtmlTextInput textbox = config.getInputByName("_.label"); + textbox.setText("hello"); + r.submit(config); + assertEquals( + "global config page let us edit it", + "hello", + SampleConfiguration.get().getLabel()); + }); + sessions.then(r -> { + assertEquals( + "still there after restart of Jenkins", + "hello", + SampleConfiguration.get().getLabel()); + }); + } +}