Commit ba1bd1fc by Jacek Bzdak

Provisioning Jenkins for DSL jobs PR fixes

parent 428cd59b
...@@ -30,7 +30,7 @@ This file needs to contain, at least, the following variables ...@@ -30,7 +30,7 @@ This file needs to contain, at least, the following variables
#### Jenkins user password #### Jenkins user password
You'll need to override default jenkins user password, please do that You'll need to override default `jenkins` user password, please do that
as this sets up the **shell** password for this user. as this sets up the **shell** password for this user.
You'll need to set both a plain password and a hashed one. You'll need to set both a plain password and a hashed one.
...@@ -113,13 +113,13 @@ Variables used by command waiting on Jenkins start-up after running ...@@ -113,13 +113,13 @@ Variables used by command waiting on Jenkins start-up after running
Jenkins auth realm encapsulates user management in Jenkins, that is: Jenkins auth realm encapsulates user management in Jenkins, that is:
* What users are can log in * What users can log in
* What credentials they use to log in * What credentials they use to log in
Realm type stored in `jenkins_auth_realm.name` variable. Realm type stored in `jenkins_auth_realm.name` variable.
In future we will try to enable other auth domains, while In future we will try to enable other auth domains, while
preserving ability to run cli. preserving the ability to run cli.
##### Unix Realm ##### Unix Realm
...@@ -149,7 +149,7 @@ Seed job is configured in `jenkins_seed_job` variable, which has the following ...@@ -149,7 +149,7 @@ Seed job is configured in `jenkins_seed_job` variable, which has the following
attributes: attributes:
* `name`: Name of the job in Jenkins. * `name`: Name of the job in Jenkins.
* `time_trigger`: A Jenkins cron entry defining how often this job should ran. * `time_trigger`: A Jenkins cron entry defining how often this job should run.
* `removed_job_action`: what to do when a job created by a previous run of seed job * `removed_job_action`: what to do when a job created by a previous run of seed job
is missing from current run. This can be either `DELETE` or`IGNORE`. is missing from current run. This can be either `DELETE` or`IGNORE`.
* `removed_view_action`: what to do when a view created by a previous run of seed job * `removed_view_action`: what to do when a view created by a previous run of seed job
......
...@@ -16,6 +16,10 @@ JENKINS_ANALYTICS_CREDENTIALS: ...@@ -16,6 +16,10 @@ JENKINS_ANALYTICS_CREDENTIALS:
JENKINS_ANALYTICS_CONCURRENT_JOBS_COUNT: 2 JENKINS_ANALYTICS_CONCURRENT_JOBS_COUNT: 2
jenkins_credentials_root: '/tmp/credentials'
jenkins_credentials_file_dest: "{{ jenkins_credentials_root }}/credentials.json"
jenkins_credentials_script: "{{ jenkins_credentials_root }}/addCredentials.groovy"
jenkins_connection_retries: 240 jenkins_connection_retries: 240
jenkins_connection_delay: 1 jenkins_connection_delay: 1
jenkins_auth_realm: jenkins_auth_realm:
......
---
- set_fact:
jenkins_credentials_root: '/tmp/credentials'
- set_fact:
jenkins_credentials_file_dest: "{{ jenkins_credentials_root }}/credentials.json"
jenkins_credentials_script: "{{ jenkins_credentials_root }}/addCredentials.groovy"
- name: create credentials dir
file: name={{ jenkins_credentials_root }} state=directory
- name: upload groovy script
template:
src: addCredentials.groovy
dest: "{{ jenkins_credentials_script }}"
mode: "600"
- name: upload credentials file
template:
src: credentials_file.json.j2
dest: "{{ jenkins_credentials_file_dest }}"
mode: "600"
owner: "{{ jenkins_user }}"
- name: add credentials
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "groovy {{ jenkins_credentials_script }}"
- name: clean up
file: name={{ jenkins_credentials_root }} state=absent
---
- name: upload job file
template: src=seed_job_template.xml dest=/tmp/{{ job_name }} mode="600"
- name: check if job is present
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "get-job {{ job_name }}"
jenkins_ignore_cli_errors: yes
- set_fact:
get_job_output: "{{ jenkins_command_output }}"
- name: Create seed job if absent
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "create-job {{ job_name }}"
jenkins_command_prefix: "cat /tmp/{{ job_name }} | "
when: get_job_output.rc != 0
- name: update seed job
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "update-job {{ job_name }}"
jenkins_command_prefix: "cat /tmp/{{ job_name }} | "
when: get_job_output.rc == 0
- name: Build the seed job
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "build {{ job_name }} -s"
...@@ -20,20 +20,74 @@ ...@@ -20,20 +20,74 @@
owner: "{{ jenkins_user }}" owner: "{{ jenkins_user }}"
group: "{{ jenkins_group }}" group: "{{ jenkins_group }}"
# Unconditionally restart jenkins, this has two side-effects: # Unconditionally restart Jenkins, this has two side-effects:
# 1. Jenkins uses new auth realm # 1. Jenkins uses new auth realm
# 2. We guarantee that jenkins is started (this is not certain # 2. We guarantee that jenkins is started (this is not certain
# as Jenkins is started by handlers from jenkins_master, # as Jenkins is started by handlers from jenkins_master,
# these handlers are launched after this role. # these handlers are launched after this role).
- name: restart Jenkins - name: restart Jenkins
service: name=jenkins state=restarted service: name=jenkins state=restarted
- include: add_credentials.yaml # Upload Jenkins credentials
- name: create seed job - name: create credentials dir
include: create_seed_job.yaml file: name={{ jenkins_credentials_root }} state=directory
- name: upload groovy script
template:
src: addCredentials.groovy
dest: "{{ jenkins_credentials_script }}"
mode: "600"
- name: upload credentials file
template:
src: credentials_file.json.j2
dest: "{{ jenkins_credentials_file_dest }}"
mode: "600"
owner: "{{ jenkins_user }}"
- name: add credentials
include: execute_jenkins_cli.yaml
vars: vars:
job_name: "{{ jenkins_seed_job.name }}" jenkins_command_string: "groovy {{ jenkins_credentials_script }}"
job: "{{ jenkins_seed_job }}"
- name: clean up
file: name={{ jenkins_credentials_root }} state=absent
# Upload seed job
- name: upload job file
template: src=seed_job_template.xml dest=/tmp/{{ jenkins_seed_job.name }} mode="600"
- name: check if job is present
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "get-job {{ jenkins_seed_job.name }}"
jenkins_ignore_cli_errors: yes
- set_fact:
get_job_output: "{{ jenkins_command_output }}"
# Upload seed job to Jenkins
- name: Create seed job if absent
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "create-job {{ jenkins_seed_job.name }}"
jenkins_command_prefix: "cat /tmp/{{ jenkins_seed_job.name }} | "
when: get_job_output.rc != 0
- name: update seed job
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "update-job {{ jenkins_seed_job.name }}"
jenkins_command_prefix: "cat /tmp/{{ jenkins_seed_job.name }} | "
when: get_job_output.rc == 0
# Build the seed job
- name: Build the seed job
include: execute_jenkins_cli.yaml
vars:
jenkins_command_string: "build {{ jenkins_seed_job.name }} -s"
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
<configVersion>2</configVersion> <configVersion>2</configVersion>
<userRemoteConfigs> <userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig> <hudson.plugins.git.UserRemoteConfig>
<url>{{ job.scm.url}}</url> <url>{{ jenkins_seed_job.scm.url}}</url>
{% if job.scm.credential_id is defined and job.scm.credential_id %} {% if jenkins_seed_job.scm.credential_id is defined and jenkins_seed_job.scm.credential_id %}
<credentialsId>{{ job.scm.credential_id }}</credentialsId> <credentialsId>{{ jenkins_seed_job.scm.credential_id }}</credentialsId>
{% endif %} {% endif %}
</hudson.plugins.git.UserRemoteConfig> </hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs> </userRemoteConfigs>
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers> <triggers>
<hudson.triggers.TimerTrigger> <hudson.triggers.TimerTrigger>
<spec>{{ job.time_trigger }}</spec> <spec>{{ jenkins_seed_job.time_trigger }}</spec>
</hudson.triggers.TimerTrigger> </hudson.triggers.TimerTrigger>
</triggers> </triggers>
<concurrentBuild>false</concurrentBuild> <concurrentBuild>false</concurrentBuild>
...@@ -57,13 +57,13 @@ ...@@ -57,13 +57,13 @@
<useWorkspaceAsHome>false</useWorkspaceAsHome> <useWorkspaceAsHome>false</useWorkspaceAsHome>
</hudson.plugins.gradle.Gradle> </hudson.plugins.gradle.Gradle>
<javaposse.jobdsl.plugin.ExecuteDslScripts plugin="job-dsl@1.43"> <javaposse.jobdsl.plugin.ExecuteDslScripts plugin="job-dsl@1.43">
<targets>{{ job.scm.target_jobs }}</targets> <targets>{{ jenkins_seed_job.scm.target_jobs }}</targets>
<usingScriptText>false</usingScriptText> <usingScriptText>false</usingScriptText>
<ignoreExisting>false</ignoreExisting> <ignoreExisting>false</ignoreExisting>
<removedJobAction>{{ job.removed_job_action }}</removedJobAction> <removedJobAction>{{ jenkins_seed_job.removed_job_action }}</removedJobAction>
<removedViewAction>{{ job.removed_view_action }}</removedViewAction> <removedViewAction>{{ jenkins_seed_job.removed_view_action }}</removedViewAction>
<lookupStrategy>JENKINS_ROOT</lookupStrategy> <lookupStrategy>JENKINS_ROOT</lookupStrategy>
<additionalClasspath>{{ job.scm.additional_classpath }}</additionalClasspath> <additionalClasspath>{{ jenkins_seed_job.scm.additional_classpath }}</additionalClasspath>
</javaposse.jobdsl.plugin.ExecuteDslScripts> </javaposse.jobdsl.plugin.ExecuteDslScripts>
</builders> </builders>
<publishers/> <publishers/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment