diff --git a/jenkins/master/defaults/main.yml b/jenkins/master/defaults/main.yml index c3cd118c..29c071aa 100644 --- a/jenkins/master/defaults/main.yml +++ b/jenkins/master/defaults/main.yml @@ -12,4 +12,60 @@ jenkins_package_requirements: - curl - python-svn +jenkins_sbt_launch_jars: + - sbt-launch-0.11.0.jar + - sbt-launch-0.12.jar + - sbt-launch-0.13.13.jar +jenkins_http_port: 8080 +jenkins_http_host: 127.0.0.1 +jenkins_dest: "/var/lib/jenkins" +jenkins_webroot: /var/cache/jenkins/war +jenkins_username: jenkins +jenkins_group: jenkins +jenkins_shell: /bin/bash +jenkins_restart_delay: 120 +jenkins_admin_user: jenkins.admin +jenkins_jdk_xmx: 4096M +jenkins_jdk_gc_opts: "-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled" +jenkins_ajp_port: -1 +jenkins_servlet_context: / + +jenkins_cli_dest: "{{ jenkins_dest }}/jenkins-cli.jar" # Jenkins CLI destination +jenkins_updates_dest: "{{ jenkins_dest }}/updates_jenkins.json" # Jenkins updates file +jenkins_admin_user_pwd_file: "{{ jenkins_dest }}/.jenkins_admin_pwd" + +jenkins_plugins: + - 'chucknorris' +# - 'configurationslicing' + - 'credentials' + - 'disk-usage' + - 'email-ext' + - 'embeddable-build-status' + - 'external-monitor-job' + - 'ldap' + - 'git' + - 'github' + - 'github-api' +# - 'global-build-stats' + - 'javadoc' + - 'job-dsl' +# - 'jobConfigHistory' + - 'mailer' + - 'maven-plugin' + - 'monitoring' + - 'extended-read-permission' + - 'dependency-queue-plugin' + - 'dependencyanalyzer' + - 'depgraph-view' + - 'progress-bar-column-plugin' + - 'publish-over-ftp-plugin' + - 'redmine-plugin' + - 'slave-utilization-plugin' + - 'sonar' + - 'ssh-credentials' + - 'ssh-slaves' + - 'subversion' +# - 'timestamper' + - 'translation' + - 'naginator' diff --git a/jenkins/master/files/sbt-launch-0.11.0.jar b/jenkins/master/files/sbt-launch-0.11.0.jar new file mode 100644 index 00000000..070ecb01 Binary files /dev/null and b/jenkins/master/files/sbt-launch-0.11.0.jar differ diff --git a/jenkins/master/files/sbt-launch-0.12.jar b/jenkins/master/files/sbt-launch-0.12.jar new file mode 100644 index 00000000..7492920b Binary files /dev/null and b/jenkins/master/files/sbt-launch-0.12.jar differ diff --git a/jenkins/master/files/sbt-launch-0.13.13.jar b/jenkins/master/files/sbt-launch-0.13.13.jar new file mode 100755 index 00000000..34b74b7e Binary files /dev/null and b/jenkins/master/files/sbt-launch-0.13.13.jar differ diff --git a/jenkins/master/handlers/main.yml b/jenkins/master/handlers/main.yml index e69de29b..2d9751a8 100644 --- a/jenkins/master/handlers/main.yml +++ b/jenkins/master/handlers/main.yml @@ -0,0 +1,28 @@ +--- +- name: Update apt cache + apt: update_cache=yes + +- name: Reload nginx + service: name=nginx state=reloaded + +- name: Set permissions on the javadoc dir + raw: chown -R {{ jenkins.username }}:{{ jenkins.group }} {{ jenkins.dnet_javadoc_dir }}/ + +- name: Set permissions on the webroot public dir + raw: chown -R {{ jenkins.username }}:{{ jenkins.group }} {{ nginx.web_root }}/public/ + +- name: Start sonar + service: name=sonar state=started + +- name: Stop sonar + service: name=sonar state=stopped + +- name: Restart sonar + service: name=sonar state=restarted + +- name: Restart jenkins + service: name=jenkins state=restarted + +- name: Reload nginx + service: name=nginx state=reloaded + diff --git a/jenkins/master/tasks/main.yml b/jenkins/master/tasks/main.yml index d51ba0d4..34a4cfa7 100644 --- a/jenkins/master/tasks/main.yml +++ b/jenkins/master/tasks/main.yml @@ -13,18 +13,86 @@ - name: Install jenkins apt: pkg={{ item }} state={{ jenkins_pkg_state }} update_cache=yes cache_valid_time=3600 + register: jenkins_install with_items: '{{ jenkins_packages }}' - name: Install some jenkins requirements apt: pkg={{ item }} state={{ jenkins_pkg_state }} update_cache=yes cache_valid_time=3600 with_items: '{{ jenkins_package_requirements }}' + - name: install sbt launcher + copy: src={{ item }} dest=/usr/local/lib/{{ item }} + with_items: '{{ jenkins_sbt_launch_jars }}' + + - name: Set the startup jenkins options + template: src=jenkins.default.j2 dest=/etc/default/jenkins owner=root group=root mode=0444 + notify: Restart jenkins + - name: Ensure that jenkins is started and enabled service: name=jenkins state=started enabled=yes when: jenkins_install tags: jenkins +- block: + # Handle plugins + # If Jenkins is installed or updated, wait for pulling the Jenkins CLI, assuming 10s should be sufficiant + - name: 120 seconds delay while starting Jenkins + wait_for: port={{ jenkins_http_port }} delay={{ jenkins_restart_delay }} + when: jenkins_install | changed + + # Create Jenkins CLI destination directory + - name: "Create Jenkins CLI destination directory" + file: path={{ jenkins_dest }} state=directory + + - name: Get Jenkins CLI + get_url: url=http://localhost:{{ jenkins_http_port }}/jnlpJars/jenkins-cli.jar dest={{ jenkins_cli_dest }} mode=0440 + + # Get latest Jenkins update file + - name: Get Jenkins updates + get_url: url=http://updates.jenkins-ci.org/update-center.json dest={{ jenkins_updates_dest }} thirsty=yes mode=0660 + register: jenkins_updates + + # Jenkins Update-center + - name: Update-center Jenkins + shell: "cat {{ jenkins_updates_dest }} | sed '1d;$d' | curl -X POST -H 'Accept: application/json' -d @- http://localhost:{{ jenkins_http_port }}/updateCenter/byId/default/postBack" + when: jenkins_updates | changed + + # Create the Jenkins administrative user password file + - name: Create the Jenkins administrative user password file + copy: content={{ jenkins_admin_pwd }} dest={{ jenkins_admin_user_pwd_file }} mode=600 + + # login as the Jenkins administrative user + - name: login as the Jenkins administrative user + command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} login --username {{ jenkins_admin_user }} --password-file {{ jenkins_admin_user_pwd_file }} + when: (jenkins_plugins is defined) and (jenkins_updates | changed) + + # Install/update Jenkins plugins + - name: Install/update plugins + command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} install-plugin {{ item }} + when: (jenkins_plugins is defined) and (jenkins_updates | changed) + with_items: '{{ jenkins_plugins }}' + + # Wait for Jenkins to install plugins, assuming 10s should be sufficiant + - name: 120 seconds delay while installing plugins + wait_for: port={{ jenkins_http_port }} delay={{ jenkins_restart_delay }} + when: jenkins_updates | changed + + # Safe-restart Jenkins + - name: Safe-restart Jenkins + command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} safe-restart + when: jenkins_updates | changed + + - name: logout the Jenkins administrative user + command: java -jar {{ jenkins_cli_dest }} -s http://localhost:{{ jenkins_http_port }} logout + when: (jenkins_plugins is defined) and (jenkins_updates | changed) + ignore_errors: True + + become: True + become_user: '{{ jenkins_username }}' + when: jenkins_install + tags: [ 'jenkins', 'jenkins_plugins' ] + - block: - name: Ensure that jenkins is stoppend and disabled service: name=jenkins state=stopped enabled=no diff --git a/jenkins/master/templates/jenkins.default.j2 b/jenkins/master/templates/jenkins.default.j2 new file mode 100644 index 00000000..3d448cc3 --- /dev/null +++ b/jenkins/master/templates/jenkins.default.j2 @@ -0,0 +1,62 @@ +# defaults for jenkins continuous integration server + +# pulled in from the init script; makes things easier. +NAME=jenkins + +# location of java +JAVA=/usr/bin/java + +# arguments to pass to java +JAVA_ARGS="-server -Djava.awt.headless=true -Xmx{{ jenkins_jdk_xmx }}" +JAVA_ARGS="-Djava.net.preferIPv4Stack=true $JAVA_ARGS" # make jenkins listen on IPv4 address +JAVA_ARGS="$JAVA_ARGS {{ jenkins_jdk_gc_opts }}" + +PIDFILE=/var/run/jenkins/jenkins.pid + +# user id to be invoked as (otherwise will run as root; not wise!) +JENKINS_USER={{ jenkins_username }} + +# location of the jenkins war file +JENKINS_WAR=/usr/share/jenkins/jenkins.war + +# jenkins home location +JENKINS_HOME={{ jenkins_dest }} + +# set this to false if you don't want Hudson to run by itself +# in this set up, you are expected to provide a servlet container +# to host jenkins. +RUN_STANDALONE=true + +# log location. this may be a syslog facility.priority +JENKINS_LOG=/var/log/jenkins/$NAME.log +#HUDSON_LOG=daemon.info + +# OS LIMITS SETUP +# comment this out to observe /etc/security/limits.conf +# this is on by default because http://github.com/jenkinsci/jenkins/commit/2fb288474e980d0e7ff9c4a3b768874835a3e92e +# reported that Ubuntu's PAM configuration doesn't include pam_limits.so, and as a result the # of file +# descriptors are forced to 1024 regardless of /etc/security/limits.conf +MAXOPENFILES=8192 + +HTTP_HOST={{ jenkins_http_host }} + +# port for HTTP connector (default 8080; disable with -1) +HTTP_PORT={{ jenkins_http_port }} + +# port for AJP connector (disabled by default) +AJP_PORT={{ jenkins_ajp_port }} + +# servlet context, important if you want to use apache proxying +PREFIX=/{{ jenkins_servlet_context }} + +# arguments to pass to jenkins. +# --javahome=$JAVA_HOME +# --httpPort=$HTTP_PORT (default 8080; disable with -1) +# --httpsPort=$HTTP_PORT +# --ajp13Port=$AJP_PORT +# --argumentsRealm.passwd.$ADMIN_USER=[password] +# --argumentsRealm.$ADMIN_USER=admin +# --webroot=~/.jenkins/war +# --prefix=$PREFIX + +JENKINS_ARGS="--webroot={{ jenkins_webroot }} --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --httpListenAddress=$HTTP_HOST"