1 修改jenkins的根目录,默认地在C:\Documents and Settings\AAA\.jenkins 。
.jenkins
├─jobs
│ └─JavaHelloWorld│ ├─builds│ │ ├─2011-11-03_16-48-17│ │ ├─2011-11-03_16-49-05│ │ ├─2011-11-03_16-49-29│ │ ├─2011-11-03_17-01-49│ │ └─2011-11-03_17-11-42│ └─workspace│ ├─build│ │ ├─classes│ │ │ └─oata│ │ └─jar│ └─src│ └─oata├─plugins├─usercontent├─war 可以通过设置环境变量来修改,例如:set JENKINS_HOME=C:\jenkins
然后重新启动jenkins。
2 备份和恢复jenkins
只需要备份JENKINS_HOME下的所有文件和文件夹,恢复的时候需要先停止jenkins。
3 移动,删除或修改jobs
对于移动或删除jobs,只需要简单地移动或删除%JENKINS_HOEM%\jobs目录。
对于修改jobs的名字,只需要简单地修改%JENKINS_HOEM%\jobs下对应job的文件夹的名字。
对于不经常使用的job,只需要对%JENKINS_HOEM%\jobs下对应的jobs的目录zip或tar后存储到其他的地方。
4 可以在jenkins的url中执行一些命令来操作jenkins,如下
] 命令可以为:exit shutdown jenkins
restart restart jenkinsreload to reload the configuration5 Jenkins 启动时的命令行参数 --httpPort=$HTTP_PORT,用来设置jenkins运行时的web端口。--httpsPort=$HTTP_PORT,表示使用https协议。--httpListenAddress=$HTTP_HOST,用来指定jenkins监听的ip范围,默认为所有的ip都可以访问此jenkins server。6 修改jenkins的timezone
如果jenkins所在的server的timezone不同于用户的timezone,这时候需要修改jenkins的timezone,需要在jenkins启动的时候增加下列参数-Dorg.apache.commons.jelly.tags.fmt.timeZone=TZ
7 最好通过一个脚本来启动jenkins,确保jenkins每次都运行在相同的环境下,例如
startjenkins.batset JENKINS_HOME=c:\jenkinscd /d %JENKINS_HOME%java -jar %JENKINS_HOME%\jenkins.war --httpPort=80008 jenkins在后台运行
如果jenkins是部署在servlet容器中,例如apache,tomcat中。因为servlet容器一般都在后台运行了,所以jenkins也就已经在后台运行了。对于windows用户需要在jenkins的管理页面中点击insall as windows service来将jenkins部署为service。 但是感觉比较好的方法还是手动将启动jenkins的脚本部署为windows service,从而可以更灵活地设置更多的参数。9 jenkins的系统信息可以在jenkins的管理页面下的系统信息中,查看所有的jenkins的信息,例如jenkins的启动配置,所依赖的系统的环境变量,所安装的plugins。
10 jenkins内置的环境变量
BUILD_NUMBER, 唯一标识一次build,例如23;
BUILD_ID,基本上等同于BUILD_NUMBER,但是是字符串,例如2011-11-15_16-06-21;JOB_NAME, job的名字,例如JavaHelloWorld;BUILD_TAG, 作用同BUILD_ID,BUILD_NUMBER,用来全局地唯一标识一此build,例如jenkins-JavaHelloWorld-23;EXECUTOR_NUMBER, 例如0;NODE_NAME,slave的名字,例如MyServer01;NODE_LABELS,slave的label,标识slave的用处,例如JavaHelloWorld MyServer01;JAVA_HOME, java的home目录,例如C:\Program Files (x86)\Java\jdk1.7.0_01;WORKSPACE,job的当前工作目录,例如c:\jenkins\workspace\JavaHelloWorld;HUDSON_URL = JENKINS_URL, jenkins的url,例如 ;BUILD_URL,build的url 例如;JOB_URL, job的url,例如;SVN_REVISION,svn 的revison, 例如4;
在网上貌似没有找到Jenkins的中文的太多的文档,有的都是关于Hudson的一些零零散散的,所以自己边学习边实践总结了以下系列文章,希望有助于大家对于Jenkins的使用。 本系列文章是基于我3年多的SCM+build release经验,总结了最常用的最基本功能,文章基本上来自于Jenkins官方网站的英文帮助的翻译和实际的例子和操作的截图,让大家能够快速直观地学习Jenkins。
Jenkins是Continous Integration Server,是Hadson的继续。 类似的产品: CruiseControl,BuildBot,TeamCity,BuildForge, ElectricCommander等。
[个人觉是Jenkins在开源的CIServer中的理想的选择。]
Jenkins的突出特点:
开源免费;
跨平台,支持所有的平台;
master/slave支持分布式的build;
web形式的可视化的管理页面;
安装配置超级简单;
tips及时快速的帮助;
已有的200多个插件;
Jenkins的入门教程:
官方帮助:
apache的使用实例: 使用jenkins来build jenkins的实例:
此系列文章的PDF的下载:
报错1:jenkins中配置的用户没有读取仓库的权限
Cloning repository git@192.168.1.1:project/app-ms.git > /usr/bin/git init /var/lib/jenkins/workspace/app-ms # timeout=10Fetching upstream changes from git@192.168.1.1:project/app-ms.git > /usr/bin/git --version # timeout=10 > /usr/bin/git fetch --tags --progress git@192.168.1.1:project/app-ms.git+refs/heads/*:refs/remotes/origin/*ERROR: Error cloning remote repo 'origin'hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress git@192.168.1.1:project/app-ms.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:stdout: stderr: GitLab: The project you were looking for could not be found.fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists. at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:72) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:442) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:655) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1152) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1192) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:120) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:90) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:77) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
报错2:项目目录层级与piple中的配置不一致
start compile and package[Pipeline] sh+ mvn -f app-ms/pom.xml -U -am -Dmaven.test.skip=true clean package -P FAT --settings /root/.m2/settings.xmlPOM file app-ms/pom.xml specified with the -f/--file command line argument does not exist[INFO] Scanning for projects...[ERROR] [ERROR] Some problems were encountered while processing the POMs:[FATAL] Non-readable POM /var/lib/jenkins/workspace/app-ms/app-ms/pom.xml: /var/lib/jenkins/workspace/app-ms/app-ms/pom.xml (No such file or directory) @ @ [ERROR] The build could not read 1 project -> [Help 1][ERROR] [ERROR] The project (/var/lib/jenkins/workspace/app-ms/app-ms/pom.xml) has 1 error[ERROR] Non-readable POM /var/lib/jenkins/workspace/app-ms/app-ms/pom.xml: /var/lib/jenkins/workspace/app-ms/app-ms/pom.xml (No such file or directory)[ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (上传部署)Stage "上传部署" skipped due to earlier failure(s)[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // withEnv[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineERROR: script returned exit code 1Finished: FAILURE
#!groovypipeline { agent any environment { REPOSITORY = "git@192.168.1.1:project/app-ms.git" } stages { stage('获取代码') { steps { addShortText background:'#cfe0f8',text: "$ENV $BRANCH" echo "start fetch code from git:$REPOSITORY" deleteDir() git branch: "$BRANCH", credentialsId: 'credential.test', url: "$REPOSITORY" } } stage('编译打包') { steps { echo "start compile and package" sh "mvn -f pom.xml -U -am -Dmaven.test.skip=true clean package -P $ENV --settings /root/.m2/settings.xml" } } stage('上传部署') { steps { echo "start deploy" sh "$JENKINS_HOME/pinpoint-ms.sh $JOB_NAME $ENV $DOMAIN $PACKAGE $DOMAINURL app-ms" } } }}
问题3:打包的没有在<build>中指定finalName 导致jar的名字不对
/var/lib/jenkins/pinpoint-ms.sh: line 41: cd: /var/lib/jenkins/workspace/app-ms/app-ms: No such file or directoryingress enabled is falseimage name is newhub.app.com/app-ms-fat:201904252042_5f1524arelease name is app-ms-fat/var/lib/jenkins/pinpoint-ms.sh: line 64: cd: /code/app-ms/app-ms: No such file or directory/var/lib/jenkins/pinpoint-ms.sh: line 65: cd: /code/app-ms/app-ms/app-ms: No such file or directory/var/lib/jenkins/pinpoint-ms.sh: line 66: cd: /code/app-ms/app-ms/app-ms/app-ms: No such file or directorymv: cannot stat ‘target/app-ms.jar’: No such file or directory11111111Dockerfile already exsitsSending build context to Docker daemon 50.72 MBStep 1/4 : FROM newhub.app.com/oracle-jdk:8-cst ---> c11aa95ae33a48Step 2/4 : COPY target/app-ms.jar app.jarlstat target/app-ms.jar: no such file or directory[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // withEnv[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineERROR: script returned exit code 1Finished: FAILURE