Poonam Agrawal
Poonam Agrawal

Reputation: 372

Unable to install git and related plugins in Jenkins using Ansible

I am trying to install the following Jenkins plugins(while installing Jenkins) using Ansible

git,git-client,ssh,scm-api,shiningpanda plugin

After execution packages ssh, scm-api, shiningpanda plugins got installed.git and git-client are not in the list of installed plugins. Below is the code and link to the the code I have used:

- name: Get the jenkins-cli jarfile from the Jenkins server
  get_url:
    url: "http://{{host-name}}:8080/jnlpJars/jenkins-cli.jar"
    dest: "/opt/jenkins-cli.jar"
  register: jarfile_get
  until: "'OK' in jarfile_get.msg or 'file already exists' in jarfile_get.msg"
  retries: 5
  delay: 10

- name: Install Jenkins plugins
  command: >
    java -jar /opt/jenkins-cli.jar -s http://{{host-name}}:8080/ install-plugin {{ item }}
    creates=/var/lib/jenkins/plugins/{{ item }}.jpi
  with_items: jenkins_plugins
  notify: restart jenkins

- name: Force a change of owner for all plugins
  shell: chown -R konfilarity:konfilarity /var/lib/jenkins/plugins/*
  notify: restart jenkins

Link to the ansible script referred :Install-jenkins-plugin-ansible

Upvotes: 1

Views: 868

Answers (2)

Poonam Agrawal
Poonam Agrawal

Reputation: 372

The below code worked:

 - name: Force a change of owner for all plugins
      shell: chown -R jenkins:jenkins /var/lib/jenkins/plugins/*

The only reason was the owner and group were not jenkins.

Upvotes: 0

nitzmahone
nitzmahone

Reputation: 13940

You'll probably want to add register: jenkins_output and failed_when: clauses to the Jenkins command task, and have the failed_when inspect jenkins_output.stdout and jenkins_output.stderr for success/fail. I don't know about install-plugin, but many of the Jenkins-cli commands don't return a non-zero exit code on failure, so Ansible has no idea it broke.

Upvotes: 1

Related Questions