diff options
Diffstat (limited to 'tools/moon_jenkins')
-rw-r--r-- | tools/moon_jenkins/Dockerfile | 9 | ||||
-rw-r--r-- | tools/moon_jenkins/Jenkinsfile | 24 | ||||
-rw-r--r-- | tools/moon_jenkins/README.md | 37 | ||||
-rw-r--r-- | tools/moon_jenkins/docker-compose.yml | 22 | ||||
-rw-r--r-- | tools/moon_jenkins/images/Create Multibranch Pipeline.png | bin | 0 -> 55639 bytes | |||
-rw-r--r-- | tools/moon_jenkins/images/Git Source Multibranch Pipeline.png | bin | 0 -> 31054 bytes | |||
-rw-r--r-- | tools/moon_jenkins/images/Multibranch Pipeline Log.png | bin | 0 -> 55231 bytes | |||
-rw-r--r-- | tools/moon_jenkins/images/Select Source Multibranch Pipeline.png | bin | 0 -> 23375 bytes | |||
-rw-r--r-- | tools/moon_jenkins/plugins.txt | 100 | ||||
-rw-r--r-- | tools/moon_jenkins/security.groovy | 20 | ||||
-rw-r--r-- | tools/moon_jenkins/setenv.groovy | 34 |
11 files changed, 246 insertions, 0 deletions
diff --git a/tools/moon_jenkins/Dockerfile b/tools/moon_jenkins/Dockerfile new file mode 100644 index 00000000..573d4ac8 --- /dev/null +++ b/tools/moon_jenkins/Dockerfile @@ -0,0 +1,9 @@ +FROM jenkinsci/blueocean + +ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false" + +COPY security.groovy /usr/share/jenkins/ref/init.groovy.d/security.groovy +COPY setenv.groovy /usr/share/jenkins/ref/init.groovy.d/setenv.groovy + +COPY plugins.txt /usr/share/jenkins/ref/plugins.txt +RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
\ No newline at end of file diff --git a/tools/moon_jenkins/Jenkinsfile b/tools/moon_jenkins/Jenkinsfile new file mode 100644 index 00000000..7e0e07c0 --- /dev/null +++ b/tools/moon_jenkins/Jenkinsfile @@ -0,0 +1,24 @@ +pipeline { + agent { + docker { + image 'wukongsun/moon_python_unit_test' + args '-e moon_home=${moon_home}' + } + } + stages { + stage('Python Unit Test') { + steps { + script { + sh("cd ${moon_home}/tests/python_unit") + sh("bash run_tests") + } + } + } + stage('Functional Test') { + script { + sh("cd ${moon_home}/tests/functional") + sh("bash run_tests") + } + } + } +}
\ No newline at end of file diff --git a/tools/moon_jenkins/README.md b/tools/moon_jenkins/README.md new file mode 100644 index 00000000..684b351c --- /dev/null +++ b/tools/moon_jenkins/README.md @@ -0,0 +1,37 @@ +# Moon Jenkins +The aim of this repo is to give a quick way to start with jenkins in containers. +These were the aims of the automation: +- minimal interaction with Jenkins GUI - the plugins in plugins.txt are installed automatically, the admin user is setup based on environment variables, proxy variables are inherited from environment +- the build of the custom image is integrated in the same workflow + +## Prerequisites +- one host running a newer version of the docker-engine +- docker-compose 1.18.0 + +## Usage +- Setup secrets: +```bash +export JENKINS_USER=admin +export JENKINS_PASSWORD=admin +``` +- Deploy jenkins: +```bash +docker-compose up -d + ``` +- Test: Jenkins GUI can be available on `http://<docker host IP>:8080` + + +## Pipeline Creation +You may find bellow an example of pipeline creation using BlueOcean interface. +As example I used a clone (https://github.com/brutus333/moon.git) of the moon project (https://git.opnfv.org/moon/) + +Click on "Create a new job" in the classical Jenkins UI and follow the steps highlighted bellow: + +![Create Multibranch Pipeline](images/Create%20Multibranch%20Pipeline.png) +![Select Source](images/Select%20Source%20Multibranch%20Pipeline.png) +![Configure Source](images/Git%20Source%20Multibranch%20Pipeline.png) +![Multibranch Pipeline Log](images/Multibranch%20Pipeline%20Log.png) + +Clicking on BlueOcean shows the pipeline in the blueocean interface: + +![Blue Ocean Pipeline success](images/blue%20ocean%20success%20pipeline.png) diff --git a/tools/moon_jenkins/docker-compose.yml b/tools/moon_jenkins/docker-compose.yml new file mode 100644 index 00000000..2329f7bd --- /dev/null +++ b/tools/moon_jenkins/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3.1' + +services: + + jenkins: + build: + context: . + args: + image: blueocean:v0.3 + ports: + - 8080:8080 + - 50000:50000 + environment: + - jenkins_user=${JENKINS_USER} + - jenkins_password=${JENKINS_PASSWORD} + volumes: + - jenkins-data:/var/jenkins_home + - /var/run/docker.sock:/var/run/docker.sock + user: root + +volumes: + jenkins-data: diff --git a/tools/moon_jenkins/images/Create Multibranch Pipeline.png b/tools/moon_jenkins/images/Create Multibranch Pipeline.png Binary files differnew file mode 100644 index 00000000..c71415c0 --- /dev/null +++ b/tools/moon_jenkins/images/Create Multibranch Pipeline.png diff --git a/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png b/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png Binary files differnew file mode 100644 index 00000000..dd37f217 --- /dev/null +++ b/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png diff --git a/tools/moon_jenkins/images/Multibranch Pipeline Log.png b/tools/moon_jenkins/images/Multibranch Pipeline Log.png Binary files differnew file mode 100644 index 00000000..a1905934 --- /dev/null +++ b/tools/moon_jenkins/images/Multibranch Pipeline Log.png diff --git a/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png b/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png Binary files differnew file mode 100644 index 00000000..eadbe916 --- /dev/null +++ b/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png diff --git a/tools/moon_jenkins/plugins.txt b/tools/moon_jenkins/plugins.txt new file mode 100644 index 00000000..2463d029 --- /dev/null +++ b/tools/moon_jenkins/plugins.txt @@ -0,0 +1,100 @@ +ssh-credentials +git +blueocean-dashboard +pipeline-model-api +pipeline-graph-analysis +workflow-support +display-url-api +blueocean-config +workflow-cps +branch-api +blueocean-i18n +workflow-job +blueocean-bitbucket-pipeline +favorite +docker-commons +pipeline-input-step +blueocean-pipeline-api-impl +workflow-api +jackson2-api +git-client +blueocean-pipeline-scm-api +blueocean +pipeline-build-step +jquery-detached +matrix-project +antisamy-markup-formatter +pipeline-model-extensions +docker-workflow +github +git-server +authentication-tokens +workflow-cps-global-lib +pipeline-model-definition +workflow-scm-step +pipeline-model-declarative-agent +cloudbees-bitbucket-branch-source +script-security +scm-api +blueocean-rest +variant +sse-gateway +htmlpublisher +matrix-auth +pubsub-light +blueocean-github-pipeline +token-macro +credentials +mercurial +plain-credentials +blueocean-events +github-api +blueocean-git-pipeline +structs +durable-task +pipeline-milestone-step +blueocean-pipeline-editor +blueocean-web +pipeline-stage-tags-metadata +ace-editor +blueocean-commons +blueocean-jira +blueocean-rest-impl +workflow-step-api +blueocean-personalization +workflow-basic-steps +blueocean-display-url +jira +pipeline-stage-step +jsch +blueocean-jwt +cloudbees-folder +credentials-binding +github-branch-source +apache-httpcomponents-client-4-api +blueocean-autofavorite +workflow-multibranch +mailer +workflow-durable-task-step +junit +command-launcher +bouncycastle-api +build-timeout +timestamper +resource-disposer +ws-cleanup +ant +gradle +pipeline-rest-api +handlebars +momentjs +pipeline-stage-view +workflow-aggregator +pipeline-github-lib +mapdb-api +subversion +ssh-slaves +pam-auth +ldap +email-ext +locale diff --git a/tools/moon_jenkins/security.groovy b/tools/moon_jenkins/security.groovy new file mode 100644 index 00000000..0fb5ff6e --- /dev/null +++ b/tools/moon_jenkins/security.groovy @@ -0,0 +1,20 @@ +#!groovy + +import jenkins.model.* +import hudson.security.* + +def instance = Jenkins.getInstance() + +def user = System.getenv()['jenkins_user'] +def pass = System.getenv()['jenkins_password'] +// Create user account +def hudsonRealm = new HudsonPrivateSecurityRealm(false) +hudsonRealm.createAccount(user,pass) +instance.setSecurityRealm(hudsonRealm) + +// Enable matrix auth strategy and set my_user as admin +def strategy = new GlobalMatrixAuthorizationStrategy() +strategy.add(Jenkins.ADMINISTER, user) +instance.setAuthorizationStrategy(strategy) + +instance.save() diff --git a/tools/moon_jenkins/setenv.groovy b/tools/moon_jenkins/setenv.groovy new file mode 100644 index 00000000..ab2dc137 --- /dev/null +++ b/tools/moon_jenkins/setenv.groovy @@ -0,0 +1,34 @@ +#!groovy + +import jenkins.* +import jenkins.model.* +import hudson.* +import hudson.model.* + +instance = Jenkins.getInstance() +globalNodeProperties = instance.getGlobalNodeProperties() + +envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class) + +newEnvVarsNodeProperty = null +envVars = null + +if (envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0) { + newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty(); + globalNodeProperties.add(newEnvVarsNodeProperty) + envVars = newEnvVarsNodeProperty.getEnvVars() +} else { + envVars = envVarsNodePropertyList.get(0).getEnvVars() +} + +http_proxy = System.getenv()['http_proxy'] +https_proxy = System.getenv()['https_proxy'] + +if (http_proxy) { + envVars.put("http_proxy", System.getenv()['http_proxy']) +} +if (https_proxy) { + envVars.put("https_proxy", System.getenv()['https_proxy']) +} + +instance.save() |