Jenkins六:构建中执行shell或者windows的批处理程序

Jenkins六:构建中执行shell或者windows的批处理程序

2023年7月13日发(作者:)

Jenkins六:构建中执⾏shell或者windows的批处理程序Shell/ batJenkins 可以在构建中执⾏shell命令或者windows的batch 命令。1. 选择⼀个项⽬,点击“配置”。2. 找到“构建” –> “增加构建步骤”。选择 “Execute shell” 或者 “Execute Windows batch command”。具体选择哪⼀个取决于你的执⾏环境,如果是linux环境,选择 “Execute shell”。如果是windows环境,选择 “Execute Windows batch command”。我这边选择的是“ExecuteWindows batch command”。3. 在 “命令”栏中输⼊你要执⾏的命令。echo "Hello World"echo %BUILD_TAG%python hello_备注:在命令栏下⽅,可以看到“参阅可⽤环境变量列表”。点击之后,可以看到所有可以⽤的变量名列表及其解释。⽐如上⾯我们使⽤的 BUILD_TAG。BUILD_NUMBERThe current build number, such as "153"BUILD_IDThe current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older buildsBUILD_DISPLAY_NAMEThe display name of the current build, which is something like "#153" by _NAMEName 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_TAGString of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". Convenient to put into a resource file, a jar file, etc for easier OR_NUMBERThe 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 numNODE_NAMEName of the slave if the build is on a slave, or "master" if run on masterNODE_LABELSWhitespace-separated list of labels that the node is ACEThe absolute path of the directory assigned to the build as a S_HOMEThe absolute path of the directory assigned on the master node for Jenkins to store S_URLFull URL of Jenkins, like server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)BUILD_URLFull URL of this build, like server:port/jenkins/job/foo/15/ (Jenkins URL must be set)JOB_URLFull URL of this job, like server:port/jenkins/job/foo/ (Jenkins URL must be set)SVN_REVISIONSubversion revision number that's currently checked out to the workspace, such as "12345"SVN_URLSubversion URL that's currently checked out to the workspace.

4. 在Jenkins的 workspace中的该项⽬下,我的路径是“D:JekinsworkspaceAnt_project”,放置 hello_。内容如下:print("8"*30)print("this is easy")备注:因为我的python是python3.0,所以print语句是这个样⼦。因为命令的默认执⾏路径是在 Jenkins的workspace下⾯,所以脚本需要放置在该路径。当然也可以放置到其他路径,执⾏脚本时前⾯加上路径即可。5. 点击“⽴即构建”。查看“Console output”:BUILD SUCCESSFULTotal time: 1 second[Ant_project] $ cmd /c call C:

D:JekinsworkspaceAnt_project>echo "Hello World"

"Hello World"D:JekinsworkspaceAnt_project>echo jenkins-Ant_project-8

jenkins-Ant_project-8D:JekinsworkspaceAnt_project>python hello_ 888888888888888888888888888888this is easyD:JekinsworkspaceAnt_project>exit 0

Finished: SUCCESS从“cmd /c call C: ”可以看出,Jenkins⾃动⽣成了⼀个 脚本,保存要被执⾏的命令,该脚本保存在临时路径下。后边具体执⾏了bat命令。这⾥给出了Jenkins执⾏bat的实例,同时在bat中调⽤了 python脚本,扩展开来,当然也可以调⽤其他语⾔,⽐如ruby ,perl。

python除了上⾯执⾏python命令的⽅式,Jenkins还给出了另外⼀种使⽤python命令的⽅式,那就是使⽤插件。1. 安装 Python Plugin插件。进⼊“系统管理” –> “管理插件”-> “可选插件”,在“过滤”中输⼊“Python Plugin”,可以看到页⾯显⽰出该插件,选中并点击“直接安装”即可。Adds the ability to execute python scripts as build steps.2. 任选⼀个项⽬,点击“配置”。3. 找到“构建” –> “增加构建步骤”。选择 “Execute Python script”。4. 在 “Script”栏中输⼊你要执⾏的命令。⽐如:print('hello'*8)print('3+2')5. 点击“⽴即构建”。查看“Console output”:[Ant_project] $ python C:ohellohellohellohellohellohellohello3+2Finished: SUCCESS

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689200527a220063.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信