我正在使用 jenkins api 通过 ansible 创建凭证。
- name: Add credential to add node
uri:
body: |
json={
"": "0",
"credentials": {
"scope": "GLOBAL",
"id": "jenkins_linux_slave1_auth",
"username": "jenkins",
"password": "123456",
"privateKeySource": {
"stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource",
"privateKey": "-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nPRIVATE+KEY+WITH+PLUS+SIGN\n-----END RSA PRIVATE KEY-----"
},
"description": "Jenkins Linux Slave1 Authentication",
"stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
}
}
force_basic_auth: yes
method: POST
password: "{{ jenkins_user_token }}"
status_code: 302
url: "{{ jenkins_url }}/credentials/store/system/domain/_/createCredentials"
user: "{{ jenkins_user }}"
validate_certs: no
tags:
- credential
这在詹金斯中创建了凭证,但是当我在詹金斯中检查私钥时,它会替换+
为(空间)
答案1
Jenkins API 接受普通的 URL 编码表单数据,但通常只有一个名为的字段json
。
Ansible uri 模块才不是发送普通 URL 编码的表单数据时进行 URL 编码body
。您需要自行执行此操作。