Skip to content
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

Add support for sandbox and custom config names #3

Merged
merged 2 commits into from
Sep 29, 2018

Conversation

samrocketman
Copy link
Member

@samrocketman samrocketman commented Aug 22, 2018

This adds two options to the Jenkins UI for configuring pipeline multibranch with defaults.

  1. Customizing the config file name to something other than Jenkinsfile.
  2. Enabling groovy sandbox on the default Jenkinsfile being run.

Additionally, with these new options using the @DataBoundSetter, Job DSL is now available for configuring these settings.

Example Job DSL:

multibranchPipelineJob('example') {
    factory {
        pipelineBranchDefaultsProjectFactory {
            // The ID of the default Jenkinsfile to use from the global Config File Management.
            scriptId('Jenkinsfile')

            // If enabled, the configured default Jenkinsfile will be run within a Groovy sandbox.
            useSandbox(true)
        }
    }
}

See also:

@samrocketman
Copy link
Member Author

Screenshot

screenshot of new plugin options

This adds two options to the Jenkins UI for configuring pipeline
multibranch with defaults.

1. Customizing the config file name to something other than
   `Jenkinsfile`.
2. Enabling groovy sandbox on the default Jenkinsfile being run.

Additionally, with these new options using the `@DataBoundSetter`, Job
DSL is now available for configuring these settings.

Example Job DSL:

```groovy
multibranchPipelineJob('example') {
    factory {
        pipelineBranchDefaultsProjectFactory {
            // The ID of the default Jenkinsfile to use from the global Config File Management.
            scriptId('Jenkinsfile')

            // If enabled, the configured default Jenkinsfile will be run within a Groovy sandbox.
            useSandbox(true)
        }
    }
}
```

See also:

- [JENKINS-43285][JENKINS-43285] jobdsl for pipeline multibranch defaults
- [JENKINS-41108][JENKINS-41108] Posibility to specify the name of
  jenkinsfile

[JENKINS-41108]: https://issues.jenkins-ci.org/browse/JENKINS-41108
[JENKINS-43285]: https://issues.jenkins-ci.org/browse/JENKINS-43285
this.useSandbox = useSandbox;
}

public Object readResolve() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? Should never be used AFAICT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw it in another-like class and thought there was maybe something Jenkins behind the scenes that I didn't understand so I added it. I'll remove it because I agree.

public static final String SCRIPT = "Jenkinsfile";

private String scriptId = SCRIPT;
private Boolean useSandbox = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be boolean. Otherwise you will get an NPE after load from previous settings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I will update it.

@sgleske-ias
Copy link

@jglick I removed readResolve() from DefaultsBinder and PipelineBranchDefaultsProjectFactory classes.

@samrocketman
Copy link
Member Author

I need to build and try out the latest code changes before this gets merged.

@samrocketman
Copy link
Member Author

I have successfully tested the latest changes.

@samrocketman
Copy link
Member Author

@vaimr do you still support this plugin or should I request ownership to maintain this plugin?

samrocketman added a commit to samrocketman/repository-permissions-updater that referenced this pull request Aug 23, 2018
defaults plugin

This is so that I can merge and release [a pull request][jenkins-infra#3] in case the
original maintainer does not reply.  The pipeline multibranch defaults
plugin has not had any changes in two years so it is unlikely anybody
supports it.

[jenkins-infra#3]: jenkinsci/pipeline-multibranch-defaults-plugin#3
@yan796
Copy link

yan796 commented Aug 25, 2018

Very nice, this is exactly what I need, can we get a build to test it ?
actually, the current master does not work as I commented here:
https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Defaults+Plugin

I thinks this branch should be merged asap :)

@samrocketman
Copy link
Member Author

samrocketman commented Aug 25, 2018

@yan796 if you have maven 3 and jdk8 installed, the build procedure is:

mvn clean package

The plugin will be in target/*.hpi.

@samrocketman
Copy link
Member Author

@yan796 you should still be able to customize the ID in config file management plugin.

@yan796
Copy link

yan796 commented Aug 26, 2018

@samrocketman thanks for your message. I am unfortunately only a end-user so I don't have anything setup to compile myself the plug-in.

I must be doing something wrong but when I generate a groovy script, the ID is randomly generated and read-only while the rest, i.e. name, and script, is editable.
I will check again....

@samrocketman
Copy link
Member Author

You must customize the ID when creating the script. Once it is created I don’t think you can change it.

@yan796
Copy link

yan796 commented Aug 27, 2018

@samrocketman you were right, it must be set before creating the script. Thanks a lot for your help.

@lasote
Copy link

lasote commented Sep 3, 2018

I really like and want this feature ;)

@samrocketman
Copy link
Member Author

@daniel-beck Please review this change.

batmat pushed a commit to jenkins-infra/repository-permissions-updater that referenced this pull request Sep 29, 2018
defaults plugin

This is so that I can merge and release [a pull request][#3] in case the
original maintainer does not reply.  The pipeline multibranch defaults
plugin has not had any changes in two years so it is unlikely anybody
supports it.

[#3]: jenkinsci/pipeline-multibranch-defaults-plugin#3
@samrocketman samrocketman merged commit 1ef1e2f into jenkinsci:master Sep 29, 2018
@samrocketman samrocketman deleted the sandbox branch September 29, 2018 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants