community.general.jenkins_credential module – Manage Jenkins credentials and domains through API
Note
This module is part of the community.general collection (version 11.2.1).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.jenkins_credential
.
New in community.general 11.1.0
Synopsis
This module allows managing Jenkins credentials and domain scopes through the Jenkins HTTP API.
Create, update, and delete different credential types such as
username/password
,secret text
,SSH key
,certificates
,GitHub App
, and domains.For scoped domains (
type=scope
), it supports restrictions based onhostname
,hostname:port
,path
, andscheme
.
Requirements
The below requirements are needed on the host that executes this module.
urllib3 >= 1.26.0
Parameters
Parameter |
Comments |
---|---|
Link to Github API. Default: |
|
GitHub App ID. |
|
Description of the credential or domain. Default: |
|
List of hostnames to exclude from scope. If a hostname appears in both this list and |
|
List of host:port to exclude from scope. If a hostname and port appears in both this list and |
|
List of URL paths to exclude. If a path is also matched by If you exclude a subpath of a path previously included, that subpath alone is excluded. |
|
File path to secret file (for example For |
|
Force update if the credential already exists, used with If set to Always returns Choices:
|
|
The ID of the Jenkins credential or domain. |
|
List of hostnames to include in scope. |
|
List of |
|
List of URL paths to include when matching credentials to domains. Matching is hierarchical: subpaths of excluded paths are also excluded, even if explicitly included. |
|
Jenkins password for token creation. Required if |
|
Jenkins user for authentication. |
|
Location of the credential. Either If Choices:
|
|
Name of the token to generate. Required if When generating a new token, do not pass Creating two tokens with the same name generates two distinct tokens with different Replacing a token with another one of the same name requires deleting the original first using |
|
GitHub App owner. |
|
SSH passphrase if needed. |
|
Password for credentials types that require it (for example |
|
Path to private key file for PEM certificates or GitHub Apps. |
|
List of schemes (for example |
|
Jenkins credential domain scope. Deleting a domain scope deletes all credentials within it. Default: |
|
Secret text (used when |
|
The state of the credential. Choices:
|
|
Jenkins API token. Required unless |
|
Type of the credential or action. Choices:
|
|
Jenkins server URL. Default: |
|
Username for credentials types that require it (for example |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Returns details on what has changed (or possibly needs changing in |
Examples
- name: Generate token
community.general.jenkins_credential:
id: "test-token"
jenkins_user: "admin"
jenkins_password: "password"
type: "token"
register: token_result
- name: Add CUSTOM scope credential
community.general.jenkins_credential:
id: "CUSTOM"
type: "scope"
jenkins_user: "admin"
token: "{{ token }}"
description: "Custom scope credential"
inc_path:
- "include/path"
- "include/path2"
exc_path:
- "exclude/path"
- "exclude/path2"
inc_hostname:
- "included-hostname"
- "included-hostname2"
exc_hostname:
- "excluded-hostname"
- "excluded-hostname2"
schemes:
- "http"
- "https"
inc_hostname_port:
- "included-hostname:7000"
- "included-hostname2:7000"
exc_hostname_port:
- "excluded-hostname:7000"
- "excluded-hostname2:7000"
- name: Add user_and_pass credential
community.general.jenkins_credential:
id: "userpass-id"
type: "user_and_pass"
jenkins_user: "admin"
token: "{{ token }}"
description: "User and password credential"
username: "user1"
password: "pass1"
- name: Add file credential to custom scope
community.general.jenkins_credential:
id: "file-id"
type: "file"
jenkins_user: "admin"
token: "{{ token }}"
scope: "CUSTOM"
description: "File credential"
file_path: "../vars/my-secret.pem"
- name: Add text credential to folder
community.general.jenkins_credential:
id: "text-id"
type: "text"
jenkins_user: "admin"
token: "{{ token }}"
description: "Text credential"
secret: "mysecrettext"
location: "folder"
url: "http://localhost:8080/job/test"
- name: Add githubApp credential
community.general.jenkins_credential:
id: "githubapp-id"
type: "github_app"
jenkins_user: "admin"
token: "{{ token }}"
description: "GitHub app credential"
appID: "12345"
file_path: "../vars/github.pem"
owner: "github_owner"
- name: Add sshKey credential
community.general.jenkins_credential:
id: "sshkey-id"
type: "ssh_key"
jenkins_user: "admin"
token: "{{ token }}"
description: "SSH key credential"
username: "sshuser"
file_path: "../vars/ssh_key"
passphrase: 1234
- name: Add certificate credential (p12)
community.general.jenkins_credential:
id: "certificate-id"
type: "certificate"
jenkins_user: "admin"
token: "{{ token }}"
description: "Certificate credential"
password: "12345678901234"
file_path: "../vars/certificate.p12"
- name: Add certificate credential (pem)
community.general.jenkins_credential:
id: "certificate-id-pem"
type: "certificate"
jenkins_user: "admin"
token: "{{ token }}"
description: "Certificate credential (pem)"
file_path: "../vars/cert.pem"
private_key_path: "../vars/private.key"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Return more details in case of errors. Returned: failed |
|
The generated API token if This is needed to authenticate API calls later. This should be stored securely, as it is the only time it is returned. Returned: success |
|
The generated ID of the token. You pass this value back to the module as This should be stored securely, as it is the only time it is returned. Returned: success |