Groovy Init Script Configuration Help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Art
Reply | Threaded
Open this post in threaded view
|

Groovy Init Script Configuration Help

Art
Hi,

I am trying to auto-configure my Jenkins environment.

I started with the base Jenkins Docker Image (Alpine) and installing my plugins via install-plugins.sh script.
I am adding a pipeline job, a agent (slave) node, and setting some global variables.

What I am having trouble with is how to configure the global settings of a plugin. I have seen some examples of managing tools, but I'm not clear on how to choose/verify the package/class to use for the plugin.

Here is my Dockerfile:
FROM jenkins:2.32.3-alpine

ENV JAVA_OPTS '-Djenkins.install.runSetupWizard=false'

COPY init.groovy.d/* /usr/share/jenkins/ref/init.groovy.d/

## Install required plugins (auto installs dependencies)
RUN /usr/local/bin/install-plugins.sh \
        config-file-provider \
        credentials-binding \
        docker-workflow \
        git \
        gitlab-plugin \
        job-dsl \
        parameterized-trigger \
        ssh-agent \
        ssh-slaves \
        workflow-aggregator

The two items I am trying to configure is my `Gitlab` connection information and my `Pipeline Global Library`

For the Gitlab plugin this is how I'm starting, but not sure if it's the right direction.
import jenkins.model.*

def instance = Jenkins.getInstance()
// Is this the right class? or do I need to do something entirely different?
def gitlab = instance.getExtensionList(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.DescriptorImpl.class)
// TODO: set settings on gitlab and assign credentials by id.
For the Pipeline Global Library, I'm not even sure how to start with that one.

Any help would be greatly appreciated.

Cheers!

Art

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/11020095-0f75-47e3-852b-092b3eb037e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Init Script Configuration Help

Mark Waite-2
I've found it much easier to copy the configuration files into the "ref" directory structure of the Docker instance, rather than trying to write scripts which perform the same actions.

If you'd like to see an example of the technique, look at https://github.com/MarkEWaite/docker-lfs/tree/lts-with-plugins/ref for some of the configuration files that I've captured from my Jenkins installations.

Mark Waite

On Thu, Mar 16, 2017 at 8:35 AM Art <[hidden email]> wrote:
Hi,

I am trying to auto-configure my Jenkins environment.

I started with the base Jenkins Docker Image (Alpine) and installing my plugins via install-plugins.sh script.
I am adding a pipeline job, a agent (slave) node, and setting some global variables.

What I am having trouble with is how to configure the global settings of a plugin. I have seen some examples of managing tools, but I'm not clear on how to choose/verify the package/class to use for the plugin.

Here is my Dockerfile:
FROM jenkins:2.32.3-alpine

ENV JAVA_OPTS '-Djenkins.install.runSetupWizard=false'

COPY init.groovy.d/* /usr/share/jenkins/ref/init.groovy.d/

## Install required plugins (auto installs dependencies)
RUN /usr/local/bin/install-plugins.sh \
        config-file-provider \
        credentials-binding \
        docker-workflow \
        git \
        gitlab-plugin \
        job-dsl \
        parameterized-trigger \
        ssh-agent \
        ssh-slaves \
        workflow-aggregator

The two items I am trying to configure is my `Gitlab` connection information and my `Pipeline Global Library`

For the Gitlab plugin this is how I'm starting, but not sure if it's the right direction.
import jenkins.model.*

def instance = Jenkins.getInstance()
// Is this the right class? or do I need to do something entirely different?
def gitlab = instance.getExtensionList(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.DescriptorImpl.class)
// TODO: set settings on gitlab and assign credentials by id.
For the Pipeline Global Library, I'm not even sure how to start with that one.

Any help would be greatly appreciated.

Cheers!

Art

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/11020095-0f75-47e3-852b-092b3eb037e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAO49JtHyXcZ6-O293V_-aw8iuMkSgb%3DyiLvCpG-SqZ1f9AJFcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Art
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Init Script Configuration Help

Art
In reply to this post by Art
@Mark

Thanks for the information. It turned me to the right direction. I was able to view the xml config files and convert them to the groovy scripts I needed.

For others here is what I ended up with..

pipelineGlobalLibrary.groovy

import org.jenkinsci.plugins.workflow.libs.*
import jenkins.plugins.git.GitSCMSource

GlobalLibraries descriptor = (GlobalLibraries) GlobalLibraries.get()

GitSCMSource scmSource = new GitSCMSource('463a8f67-5a28-430e-b4ea-a18fc5b1a40d',
'[hidden email]:group/jenkinsWorkflowLibs.git',
'credentialsId',
'origin',
'+refs/heads/*:refs/remotes/origin/*',
'*',
'',
false)

SCMSourceRetriever retriever = new SCMSourceRetriever(scmSource)

LibraryConfiguration libraryConfiguration = new LibraryConfiguration('myworkflowlibs', retriever)
libraryConfiguration.setDefaultVersion('1.0.0')
libraryConfiguration.setImplicit(false)
libraryConfiguration.setAllowVersionOverride(true)

descriptor.getLibraries().add(libraryConfiguration)
descriptor.save()

gitlab.groovy

import com.dabsquared.gitlabjenkins.connection.*
import jenkins.model.Jenkins

GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class)

GitLabConnection gitLabConnection = new GitLabConnection('MyGitLab',
'https:\\\\gitlaburl.com',
'GitLabTokenId',
false,
10,
10)
descriptor.getConnections().clear()
descriptor.addConnection(gitLabConnection)
descriptor.save()


Cheers!

Art

On Thursday, March 16, 2017 at 3:35:36 PM UTC+1, Art wrote:
Hi,

I am trying to auto-configure my Jenkins environment.

I started with the base Jenkins Docker Image (Alpine) and installing my plugins via install-plugins.sh script.
I am adding a pipeline job, a agent (slave) node, and setting some global variables.

What I am having trouble with is how to configure the global settings of a plugin. I have seen some examples of managing tools, but I'm not clear on how to choose/verify the package/class to use for the plugin.

Here is my Dockerfile:
FROM jenkins:2.32.3-alpine

ENV JAVA_OPTS '-Djenkins.install.runSetupWizard=false'

COPY init.groovy.d/* /usr/share/jenkins/ref/init.groovy.d/

## Install required plugins (auto installs dependencies)
RUN /usr/local/bin/install-plugins.sh \
        config-file-provider \
        credentials-binding \
        docker-workflow \
        git \
        gitlab-plugin \
        job-dsl \
        parameterized-trigger \
        ssh-agent \
        ssh-slaves \
        workflow-aggregator

The two items I am trying to configure is my `Gitlab` connection information and my `Pipeline Global Library`

For the Gitlab plugin this is how I'm starting, but not sure if it's the right direction.
import jenkins.model.*

def instance = Jenkins.getInstance()
// Is this the right class? or do I need to do something entirely different?
def gitlab = instance.getExtensionList(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.DescriptorImpl.class)
// TODO: set settings on gitlab and assign credentials by id.
For the Pipeline Global Library, I'm not even sure how to start with that one.

Any help would be greatly appreciated.

Cheers!

Art

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/75eef4a1-4453-4afc-b9cd-03ff5c380ef3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Init Script Configuration Help

Matt Babineau
Hi this is really an interesting discussion. We are dealing with this right now and are looking at running groovy scripts to configure the plugins. Can I ask why you aren't doing this programmatically? Our older jenkins installation handles this the same way you are, but we run into issues with the xml being updated by plugin version changes. Why would you suggest doing this in a "hardcoded" way? thanks.



On Friday, March 17, 2017 at 4:27:01 AM UTC-4, Art wrote:
@Mark

Thanks for the information. It turned me to the right direction. I was able to view the xml config files and convert them to the groovy scripts I needed.

For others here is what I ended up with..

pipelineGlobalLibrary.groovy

import org.jenkinsci.plugins.workflow.libs.*
import jenkins.plugins.git.GitSCMSource

GlobalLibraries descriptor = (GlobalLibraries) GlobalLibraries.get()

GitSCMSource scmSource = new GitSCMSource('463a8f67-5a28-430e-b4ea-a18fc5b1a40d',
'[hidden email]:group/jenkinsWorkflowLibs.git',
'credentialsId',
'origin',
'+refs/heads/*:refs/remotes/origin/*',
'*',
'',
false)

SCMSourceRetriever retriever = new SCMSourceRetriever(scmSource)

LibraryConfiguration libraryConfiguration = new LibraryConfiguration('myworkflowlibs', retriever)
libraryConfiguration.setDefaultVersion('1.0.0')
libraryConfiguration.setImplicit(false)
libraryConfiguration.setAllowVersionOverride(true)

descriptor.getLibraries().add(libraryConfiguration)
descriptor.save()

gitlab.groovy

import com.dabsquared.gitlabjenkins.connection.*
import jenkins.model.Jenkins

GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class)

GitLabConnection gitLabConnection = new GitLabConnection('MyGitLab',
'https:\\\\<a href="http://gitlaburl.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgitlaburl.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEtsDoZ2twnOiqZoXkXMHY3fHdlNg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgitlaburl.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEtsDoZ2twnOiqZoXkXMHY3fHdlNg&#39;;return true;">gitlaburl.com',
'GitLabTokenId',
false,
10,
10)
descriptor.getConnections().clear()
descriptor.addConnection(gitLabConnection)
descriptor.save()


Cheers!

Art

On Thursday, March 16, 2017 at 3:35:36 PM UTC+1, Art wrote:
Hi,

I am trying to auto-configure my Jenkins environment.

I started with the base Jenkins Docker Image (Alpine) and installing my plugins via install-plugins.sh script.
I am adding a pipeline job, a agent (slave) node, and setting some global variables.

What I am having trouble with is how to configure the global settings of a plugin. I have seen some examples of managing tools, but I'm not clear on how to choose/verify the package/class to use for the plugin.

Here is my Dockerfile:
FROM jenkins:2.32.3-alpine

ENV JAVA_OPTS '-Djenkins.install.runSetupWizard=false'

COPY init.groovy.d/* /usr/share/jenkins/ref/init.groovy.d/

## Install required plugins (auto installs dependencies)
RUN /usr/local/bin/install-plugins.sh \
        config-file-provider \
        credentials-binding \
        docker-workflow \
        git \
        gitlab-plugin \
        job-dsl \
        parameterized-trigger \
        ssh-agent \
        ssh-slaves \
        workflow-aggregator

The two items I am trying to configure is my `Gitlab` connection information and my `Pipeline Global Library`

For the Gitlab plugin this is how I'm starting, but not sure if it's the right direction.
import jenkins.model.*

def instance = Jenkins.getInstance()
// Is this the right class? or do I need to do something entirely different?
def gitlab = instance.getExtensionList(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.DescriptorImpl.class)
// TODO: set settings on gitlab and assign credentials by id.
For the Pipeline Global Library, I'm not even sure how to start with that one.

Any help would be greatly appreciated.

Cheers!

Art

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/b562098c-a809-4523-ad00-3f92066978c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Init Script Configuration Help

Mark Waite-2


On Wed, Nov 1, 2017 at 10:40 AM Matt Babineau <[hidden email]> wrote:
Hi this is really an interesting discussion. We are dealing with this right now and are looking at running groovy scripts to configure the plugins. Can I ask why you aren't doing this programmatically? Our older jenkins installation handles this the same way you are, but we run into issues with the xml being updated by plugin version changes. Why would you suggest doing this in a "hardcoded" way? thanks.


XML updates by plugin version changes have not been an issue in the 2+ years I've been using this technique.  The updates happen, I pull them into my git repository and rebuild my docker images.  However, I only have 179 plugins in my setup.  If you have significantly more than that, or a different set, your results may be very different than mine.

My initial focus was trying to assure that I could rapidly reconstruct different configurations shortly after I'd discovered that a configuration was important to me.

For example, after duplicating a bug report against the git plugin, I wanted to be 
able to commit that change to the docker definition, build it, and run that docker image on a different machine to confirm that the bug is also repeatable in a fresh environment.

Because of that desire for very little time between "first experiment" and "repeatable configuration stored in git", I didn't want to spend time investigating how to write the groovy script to express what I already had in the configuration files on the disc.

It is part laziness (don't want to do the research to learn how to configure what I've already configured) and part an intense desire to keep my open source time focused on git plugin work, rather than focused on learning how to configure the system with groovy.

I believe that I am an "outlier" in that regard.  I believe many people prefer the system groovy script technique to configure their system.  You should not mistake my different way of approaching the problem as though it is a preferred practice, or a best practice.  It works for me, and I will continue using it until it no longer works for me.  It may not work for anyone else.

Mark Waite
 


On Friday, March 17, 2017 at 4:27:01 AM UTC-4, Art wrote:
@Mark

Thanks for the information. It turned me to the right direction. I was able to view the xml config files and convert them to the groovy scripts I needed.

For others here is what I ended up with..

pipelineGlobalLibrary.groovy

import org.jenkinsci.plugins.workflow.libs.*
import jenkins.plugins.git.GitSCMSource

GlobalLibraries descriptor = (GlobalLibraries) GlobalLibraries.get()

GitSCMSource scmSource = new GitSCMSource('463a8f67-5a28-430e-b4ea-a18fc5b1a40d',
'[hidden email]:group/jenkinsWorkflowLibs.git',
'credentialsId',
'origin',
'+refs/heads/*:refs/remotes/origin/*',
'*',
'',
false)

SCMSourceRetriever retriever = new SCMSourceRetriever(scmSource)

LibraryConfiguration libraryConfiguration = new LibraryConfiguration('myworkflowlibs', retriever)
libraryConfiguration.setDefaultVersion('1.0.0')
libraryConfiguration.setImplicit(false)
libraryConfiguration.setAllowVersionOverride(true)

descriptor.getLibraries().add(libraryConfiguration)
descriptor.save()

gitlab.groovy

import com.dabsquared.gitlabjenkins.connection.*
import jenkins.model.Jenkins

GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class)

GitLabConnection gitLabConnection = new GitLabConnection('MyGitLab',
'https:\\\\gitlaburl.com',
'GitLabTokenId',
false,
10,
10)
descriptor.getConnections().clear()
descriptor.addConnection(gitLabConnection)
descriptor.save()


Cheers!

Art

On Thursday, March 16, 2017 at 3:35:36 PM UTC+1, Art wrote:
Hi,

I am trying to auto-configure my Jenkins environment.

I started with the base Jenkins Docker Image (Alpine) and installing my plugins via install-plugins.sh script.
I am adding a pipeline job, a agent (slave) node, and setting some global variables.

What I am having trouble with is how to configure the global settings of a plugin. I have seen some examples of managing tools, but I'm not clear on how to choose/verify the package/class to use for the plugin.

Here is my Dockerfile:
FROM jenkins:2.32.3-alpine

ENV JAVA_OPTS '-Djenkins.install.runSetupWizard=false'

COPY init.groovy.d/* /usr/share/jenkins/ref/init.groovy.d/

## Install required plugins (auto installs dependencies)
RUN /usr/local/bin/install-plugins.sh \
        config-file-provider \
        credentials-binding \
        docker-workflow \
        git \
        gitlab-plugin \
        job-dsl \
        parameterized-trigger \
        ssh-agent \
        ssh-slaves \
        workflow-aggregator

The two items I am trying to configure is my `Gitlab` connection information and my `Pipeline Global Library`

For the Gitlab plugin this is how I'm starting, but not sure if it's the right direction.
import jenkins.model.*

def instance = Jenkins.getInstance()
// Is this the right class? or do I need to do something entirely different?
def gitlab = instance.getExtensionList(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.DescriptorImpl.class)
// TODO: set settings on gitlab and assign credentials by id.
For the Pipeline Global Library, I'm not even sure how to start with that one.

Any help would be greatly appreciated.

Cheers!

Art

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/b562098c-a809-4523-ad00-3f92066978c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAO49JtFCkN2V4E1y6RpuO2ZgnwF%2By5d-aDr_s5rKk33b4oo5qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.