最近开始学Python,按照网上的教程,写了一个Python脚本下载Jenkins并运行的脚本,很简单。
首先使用vi命令编辑一个新文件auto_built_jenkins.py(关于vi的使用可以见前期的文章)
脚本如下:
# coding = utf-8 import os import sys print('auto deploy Jenkins script') if os.getuid()==0: pass else: print 'current user is not root ,please use root execute script!' sys.exit(1) _version=raw_input('please input which version u want to download(latest/former)') if _version == 'latest': url='http://mirrors.jenkins.io/war/latest/jenkins.war' elif _version == 'former': url='http://mirrors.jenkins.io/war-stable/latest/jenkins.war' else: print('error version input') sys.exit(1) cmd = 'wget '+url res = os.system(cmd) if res!=0: print('\ndownload resources fail,please check network!') sys.exit(1) print('\nplease use 127.0.0.1:8080 visit Jenkins!\n') sleep (3) package_name ='jenkins.war' cmd = 'java -jar '+package_name res=os.system(cmd) if res !=0: print 'start-up fail' sys.exit(1)
编辑完成后,提示窗口使用如下命令运行脚本:
运行成功后,使用本地浏览器登录如下: