简体   繁体   English

使用api配置jenkins插件/凭证值

[英]Configure jenkins plugin/ credentials values with api

I want to know if there is jenkins api (a remote access api) to set values in jenkins plugin configuration. 我想知道是否有jenkins api(远程访问api)在jenkins插件配置中设置值。 For example artifactory plugin asks for artifactory URL only in configuration manager ( http://jenkins-url/configure ) and a new url cannot be created while creating a job. 例如,人工插件仅在配置管理器中请求人工URL( http:// jenkins-url / configure ),并且在创建作业时无法创建新的URL。

Also how can we create new credentials (ssh/ username, password) on jenkins system with jenkins remote API. 另外,我们如何使用jenkins远程API在jenkins系统上创建新的凭证(ssh /用户名,密码)。

Check out this example: https://gist.github.com/iocanel/9de5c976cc0bd5011653 看看这个例子: https : //gist.github.com/iocanel/9de5c976cc0bd5011653

import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;

domain = Domain.global()
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()

priveteKey = new BasicSSHUserPrivateKey(
CredentialsScope.GLOBAL,
"jenkins-slave-key",
"root",
new BasicSSHUserPrivateKey.UsersPrivateKeySource(),
"",
""
)

usernameAndPassword = new UsernamePasswordCredentialsImpl(
  CredentialsScope.GLOBAL,
  "jenkins-slave-password", "Jenkis Slave with Password Configuration",
  "root",
  "jenkins"
)

store.addCredentials(domain, priveteKey)
store.addCredentials(domain, usernameAndPassword)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM