工作笔记-通过REST API创建Jenkins Credentials
获取中... 获取中...
准备创建Credential的模板
创建文件credential.xml,内容如下:
1
2
3
4
5
6
7
8
9<com.cloudbees.plugins.credentials.impl. UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>my-credentials-example-id</id>
<description>This is an example from REST API</description>
<username>admin</username>
<password>
<secret-redacted/>
</password>
</com.cloudbees.plugins.credentials.impl. UsernamePasswordCredentialsImpl>将模板通过POST请求发从到
$JENKINS_URL/<path to context>/credentials/store/<store id>/domain/<domain name>/createCredentials
准备更新Credential的模板
创建文件updateCredential.xml,内容如下:
1
2
3
4
5
6
7<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>my-credentials-example-id</id>
<description>This is an example from REST API (updated)</description>
<username>admin</username>
<password>newsupersecret</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>发送POST请求更新Credential
1
2
3
4
5
6curl -X POST \
-u $JENKINS_USER:$JENKINS_PASSWORD_OR_API_TOKEN \
-H "Jenkins-Crumb:${JENKINS_CRUMB}" \
-H 'content-type:application/xml' \
-d @updatedCredential.xml \
"$JENKINS_URL/<path to context>/credentials/store/<store id>/domain/<domain name>/credential/my-credentials-example-id/config.xml"
本文由 David Lin 创作,采用 知识共享署名 4.0 国际许可协议。
本站文章除注明转载/出处外,均为本站原创或翻译,转载请务必署名。