Skip to content

Commit

Permalink
Use jenkins_hostname, jenkins_http_port, and jenkins_url_prefix
Browse files Browse the repository at this point in the history
Fixes solita#9.
  • Loading branch information
solita-timo-mihaljov committed Jun 28, 2016
1 parent f5dadfc commit 3ed14bd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion library/solita_jenkins_user
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ import json
def main():
module = AnsibleModule(
argument_spec = dict(
jenkins_url=dict(type='str', required=True),
name=dict(type='str', required=True),
state=dict(choices=['present', 'absent'], default='present'),
password=dict(type='str')
)
)

rc, stdout, stderr = module.run_command("java -jar /opt/jenkins-cli.jar -s 'http://localhost:8080' groovy =",
rc, stdout, stderr = module.run_command("java -jar /opt/jenkins-cli.jar -s '%(jenkins_url)s' groovy =" % module.params,
data=(SCRIPT % json.dumps(module.params)))
if (rc != 0):
module.fail_json(msg=stderr)
Expand Down
2 changes: 1 addition & 1 deletion tasks/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@
register: remove_old_scripts

- name: Run the Job DSL scripts
shell: java -jar {{ jenkins_jar_location }} -s http://{{ jenkins_hostname }}:{{ jenkins_http_port }}/ build job-dsl -s -v
shell: "java -jar {{ jenkins_jar_location }} -s '{{ solita_jenkins_url }}/' build job-dsl -s -v"
when: ((scripts | length > 0) or (templates | length > 0)) and ((copy_scripts | changed) or (copy_templates | changed) or (remove_old_scripts | changed))
2 changes: 1 addition & 1 deletion tasks/restart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Stolen from geerlingguy.jenkins.
- name: Wait for Jenkins to start up before proceeding.
shell: "curl -D - --silent http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}/cli/"
shell: "curl -D - --silent {{ solita_jenkins_url }}/cli/"
args:
warn: no
register: result
Expand Down
10 changes: 8 additions & 2 deletions tasks/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@
- solita_jenkins_absent_users

- name: Add present Jenkins users
solita_jenkins_user: name={{ item }} password={{ lookup('password', inventory_dir + '/solita_jenkins_default_password/' + item) }} state=present
solita_jenkins_user:
jenkins_url: "{{ solita_jenkins_url }}"
name: "{{ item }}"
password: "{{ lookup('password', inventory_dir + '/solita_jenkins_default_password/' + item) }}"
with_items: "{{ solita_jenkins_users }}"

- name: Remove absent Jenkins users
solita_jenkins_user: name={{ item }} state=absent
solita_jenkins_user:
jenkins_url: "{{ solita_jenkins_url }}"
name: "{{ item }}"
state: absent
with_items: "{{ solita_jenkins_absent_users }}"
2 changes: 1 addition & 1 deletion test/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Vagrant.configure(2) do |config|
config.vm.box = 'ubuntu/trusty64'

config.vm.synced_folder "..", "/solita.jenkins"
config.vm.network :forwarded_port, guest: 8080, host: 9080
config.vm.network :forwarded_port, guest: 8081, host: 9080

config.vm.provider 'virtualbox' do |v|
v.memory = 1024
Expand Down
3 changes: 3 additions & 0 deletions test/environments/vagrant/group_vars/all/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
jenkins_http_port: 8081
jenkins_url_prefix: /jenkins
8 changes: 4 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def ansible_playbook(args, contents, options = {})
end

def open_dashboard
@agent.get('http://localhost:8080')
@agent.get('http://localhost:8081/jenkins')
end

def can_manage_jenkins?
Expand All @@ -65,23 +65,23 @@ def assert_forbidden(&block)
end

def login_as(username)
page = @agent.get('http://localhost:8080/login')
page = @agent.get('http://localhost:8081/jenkins/login')
form = page.form('login')
form.j_username = username
form.j_password = File.read("environments/vagrant/solita_jenkins_default_password/#{username}").strip
@agent.submit(form, form.buttons.first)
end

def list_users
@agent.get('http://localhost:8080/securityRealm')\
@agent.get('http://localhost:8081/jenkins/securityRealm')\
.search('//table[@id="people"]//tr/td[2]//*')\
.map { |n| n.text }\
.to_set\
.delete('solita_jenkins')
end

def list_jobs
@agent.get('http://localhost:8080')\
@agent.get('http://localhost:8081/jenkins')\
.search('table#projectstatus>tr>td:nth-child(3)')\
.map { |n| n.text }\
.to_set\
Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
solita_jenkins_plugins_required:
- job-dsl
solita_jenkins_job_dsl_workspace: /var/lib/jenkins/jobs/job-dsl/workspace
solita_jenkins_url: http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix | default('') }}

0 comments on commit 3ed14bd

Please sign in to comment.