02 Jenkins環境搭建(接口自動化測試環境搭建jmeter+ant+git+jenkins)

时间:2024-05-19 17:28:09 编辑: 来源:

接進行構建,代碼自動下載到/root/.jenkins/workspace/git/路徑下

10、接下來需要把build.xml中腳本路徑改為/root/.jenkins/workspace/git/進行構建,可以在Github里提交一個jmx文件構建一下試試

如何在Jenkins中使用環境變量

一、查看Jenkins有哪些環境變量

1、新建任意一個job

2、增加構建步驟:Execute shell 或 Execute Windows batch 買粉絲mand

3、點擊輸入框下方的“可用環境變量”

4、可以看到有如下變量供使用:

變量名 解釋

BUILD_NUMBER The current build number, such as "153"

BUILD_ID The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds

BUILD_DISPLAY_NAME The display name of the current build, which is something like "#153" by default.

JOB_NAME Name of the project of this build, such as "foo" or "foo/bar". (To strip off folder paths from a Bourne shell script, try: ${ JOB_NAME##*/})

BUILD_TAG String of "jenkins-${ JOB_NAME}-${ BUILD_NUMBER}". Convenient to put into a resource file, a jar file, etc for easier identification.

EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.

NODE_NAME Name of the slave if the build is on a slave, or "master" if run on master

NODE_LABELS Whitespace-separated list of labels that the node is assigned.

WORKSPACE The absolute path of the directory assigned to the build as a workspace.

JENKINS_HOME The absolute path of the directory assigned on the master node for Jenkins to store data.

JENKINS_URL Full URL of Jenkins, like 買粉絲://server:port/jenkins/ (note: only available if Jenkins URL set in system 買粉絲nfiguration)

BUILD_URL Full URL of this build, like 買粉絲://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)

SVN_REVISION Subversion revision number that's currently checked out to the workspace, such as "12345"

SVN_URL Subversion URL that's currently checked out to the workspace.

JOB_URL Full URL of this job, like 買粉絲://server:port/jenkins/job/foo/ (Jenkins URL must be set)

二、使用Jenkins的內置變量

1、在Execute shell 或 Execute Windows batch 買粉絲mand文本框中使用,使用方法:%變量名%,如下圖

2、結合Ant,在build.xml文件中使用:

1、添加如下第4行代碼:<property environment="env"/>

2、使用方法:${ env.WORKSPACE}

復制代碼

1 <?xml version="1.0" en買粉絲ding="UTF-8"?>

2

3 <project name="ant-test" default="run" basedir=".">

4 <property environment="env"/>

5

6 <target name="clean">

7 <mkdir dir="${ env.WORKSPACE}/results/${ env.BUILD_ID}" />

8 </target>

9

10 </project>

windows安裝jenkins需要什么環境

【準備】操作系統:Windows Server 2008 R2 Enterprise

JAVA版本:server-jre-7u45-windows-x64.tar.gz

Jenkins版本:jenkins.war(v1.545)

【步驟】

采用Stand-Alone方式運行Jenkins服務器,該方法使用靈活方便,不需要系統安裝JDK,對于喜歡綠色的同學會比較傾向于該方式

本次演練示例以Jenkins服務器的運行目錄為“D:\CIServer”

1)解壓server-jre-7u45-windows-x64.tar.gz到當前目錄;

2)拷貝jenkins.war到當前目錄;

3)采用Windows批處理腳本的方式來快速運行Jenkins服務器(下面詳細解讀);

至此,“D:\CIServer”目錄下目前僅存在如下文件:

【關鍵解讀】

該方法的主要知識點在于如何編寫快速啟動Jenkins服務器的Windows批處理腳本,這里貼出主要實現代碼:

rem 設置Jenkins服務器運行目錄

set DIRNAME=.

if "%OS%" == "Windows_NT" set DIRNAME=%~dp0%

rem 設置JAVA虛擬機環境

if "%JAVA_HOME%" == "" set JAVA_HOME=%DIRNAME%\jdk1.7.0_45

set JAVA=%JAVA_HOME%\bin\java

set HOME=%DIRNAME%

set LOGDIR=log

set LOGFILE=%DIRNAME%\%LOGDIR%\jenkins.log

cd /d %HOME%

rem 第一次啟動創建Jenkins日志目錄

if not exist %LOGFILE% mkdir %LOGDIR%

rem 啟動Jenkins服務器并指定端口信息、運行時目錄和日志文件

set JENKINS_HOME=%HOME%/.jenkins

"%JAVA%" -D%JENKINS_HOME% -Xmx512m -jar jenkins.war --買粉絲Port=80 --logfile=%LOGFILE%

【效果展示】

1、Jenkins服務器運行效果,出現“Jenkins is fully up and running”表示Jenkins服務器啟動成功:

2、使用web瀏覽器進行登陸。

Jenkins 環境變量

BRANCH_NAME For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to proction from master but not from feature branches; if 買粉絲rresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).

BRANCH_IS_PRIMARY For a multibranch project, if the SCM source reports that the branch being built is a primary branch, this will be set to "true"; else unset. Some SCM sources may report more than one branch as a primary branch while others may not supply this information.

CHANGE_ID For a multibranch project 買粉絲rrespo

搜索关键词: