ENV ANSIBLE_STDOUT_CALLBACK=yaml
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -yq \
+ openjdk-8-jdk \
python3-apt \
&& apt-get clean
RUN pip install --no-cache-dir ansible docker-py
method: 'POST'
body: "username=workshop&password=workshop"
status_code: 302
+ - name: Remove ssh-rsa from sshkey
+ set_fact:
+ workshop_ssh_key_modified: "{{ lookup('file', '{{ workshop_ssh_keyfile }}.pub') }}"
- name: Upload sshkey to Admin user
uri:
url: 'http://gerrit:8080/a/accounts/self/sshkeys'
method: 'POST'
user: 'workshop'
password: 'workshop'
- body: "{{ lookup('file', '{{ workshop_ssh_keyfile }}.pub') }}"
+ body: "{{ workshop_ssh_key_modified }}"
status_code: 201
- name: Wait for Gerrit SSH Interface
wait_for:
uid: 1000
ssh_key_bits: 2048
ssh_key_file: '{{ jenkins_ssh_keyfile }}'
+- name: Set Jenkins Workshop SSH Key fact
+ set_fact:
+ credentials_sshkey: "{{ lookup('file', jenkins_ssh_keyfile) }}"
+- name: Put down Jenkins Credential template
+ template:
+ src: jenkins-credentials.xml
+ dest: /jenkins/jenkins-credentials.xml
+- name: Install Jenkins CLI
+ get_url:
+ url: 'http://jenkins:8080/jnlpJars/jenkins-cli.jar'
+ dest: /jenkins/jenkins-cli.jar
+- name: Add Workshop Credentials to Jenkins
+ environment:
+ JENKINS_URL: http://jenkins:8080/
+ JENKINS_USER_ID: workshop
+ JENKINS_API_TOKEN: workshop
+ shell: |
+ cat jenkins-credentials.xml | java -jar jenkins-cli.jar -http \
+ update-credentials-by-xml "system::system::jenkins" "(global)" \
+ "{{ credentials_id }}"
+ args:
+ chdir: '/jenkins'
- name: Wait for Gerrit SSH Interface
wait_for:
host: 'gerrit'
--- /dev/null
+<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials@1.14">
+ <scope>GLOBAL</scope>
+ <id>{{credentials_id}}</id>
+ <description>{{credentials_description}}</description>
+ <username>{{credentials_username}}</username>
+ <privateKeySource class="com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource">
+ <privateKey>{{credentials_sshkey}}</privateKey>
+ </privateKeySource>
+</com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
global_jjb_version: "{{ lookup('env', 'GLOBAL_JJB_VERSION') | default('v0.19.2', true) }}"
global_jjb_url: https://github.com/lfit/releng-global-jjb
jjb_version: "{{ lookup('env', 'JJB_VERSION') | default('2.0.3', true) }}"
+
+credentials_id: ciworkshop-jenkins-ssh
+credentials_username: jenkins-workshop
+credentials_description: Gerrit user
Tja198bt428xTsjxxffuhekDQt8hbEO6RJFJPxhHQIWVo8708lWj
-----END RSA PRIVATE KEY-----""")
-def private_key_on_master = new BasicSSHUserPrivateKey.UsersPrivateKeySource();
-
// Credentials for connecting to an SSH Jenkins Agent
def jenkins_agent_credentials = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
CredentialsScope.GLOBAL,
"ciworkshop-jenkins-ssh", // ID
"jenkins-workshop", // username
- private_key_on_master,
+ null,
null, // password
"Gerrit User" // description
)