简体   繁体   English

Jenkins:自动化CI Docker实例

[英]Jenkins: Automate CI Docker instance

I'm trying to setup Jenkins to be fully automated once I launch it from a docker container. 一旦我从docker容器启动Jenkins,我就尝试将其设置为完全自动化。

My question is how do I automate the configuration of the global Jenkins settings. 我的问题是如何自动执行全局Jenkins设置的配置。 For example the items in manage jenkins and credentials? 例如,管理詹金斯和凭证中的项目?

I'm using this a reference: 我正在使用此参考:

https://wiki.jenkins.io/display/jenkins/remote+access+api

Currently, I have the set these items up manually. 目前,我已经手动设置了这些项目。 I would like to fully automate the CI server creation. 我想完全自动化CI服务器的创建。 Is this possible with Jenkins or is there some human intervention that is required? 詹金斯(Jenkins)是否有可能,还是需要人工干预?

Any help would be greatly appreciated. 任何帮助将不胜感激。

we used chef to setup the master , and it run some groovy scripts to install all the plugin and configuration. 我们使用Chef来设置master,然后它运行一些groovy脚本来安装所有插件和配置。 it almost done fully automatically , beside 1 or 2 plugins that I didn't find the syntax to configure all others works fine. 它几乎是完全自动完成的,除了1或2个我没有发现配置所有其他语法的插件之外,它们都能正常工作。

I installed all the plugins using Jenkins CLI , check yourJenkins/cli/ for reference. 我使用Jenkins CLI安装了所有插件,请检查yourJenkins / cli /以供参考。

for the general configuration you can install all the tools 对于常规配置,您可以安装所有工具

import jenkins.model.*
import hudson.model.*

def inst1 = Jenkins.getInstance()
def desc1 = inst1.getDescriptor("hudson.tools.JDKInstaller")
println desc1.doPostCredential('buildJenkins@gmail.com','JenkinsOracleXXXXX')

import jenkins.model.*
import hudson.model.*
import hudson.tools.*

// JDK installation
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("hudson.model.JDK")

def versions = [
    "jdk-1.8.101": "jdk-8u101-oth-JPR",
//    "jdk-1.8.102": "jdk-8u102-oth-JPR"
]

general variables 一般变量

// general properties
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)

newEnvVarsNodeProperty = null
envVars = null

if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
  newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
  globalNodeProperties.add(newEnvVarsNodeProperty)
  envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
  envVars = envVarsNodePropertyList.get(0).getEnvVars()

}
envVars.put("ARTIFACTORY_URL", "artifactory-url")
envVars.put("ARTIFACTORY_USER", "jenkins")
envVars.put("DOCKER_USER", "docker-push")


instance.save()

email address 电子邮件地址

// admin Email
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
jenkinsLocationConfiguration.setAdminAddress('admin@yours.com')
jenkinsLocationConfiguration.save()

there a lot of examples , just look for groovy Jenkins configuration .. if you have any specific question let me know. 有很多示例,只是寻找groovy Jenkins配置..如果您有任何特定问题,请告诉我。

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

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