Jenkins+github的一次定時構建示例

  首先說明,個人電腦環境是windows,因此如下的示例是基於windows10 X64。html

1、新建任務,填寫名稱,選擇類型,點擊左下角的【肯定】java

2、配置python

一、Generalgit

二、源碼管理github

  以前在github上配置了公鑰(配置的東西看這裏http://www.javashuo.com/article/p-hxmmbixp-ea.html)這裏要拉取github的代碼,須要配置私鑰,點擊Add,彈窗中填寫數據。shell

三、構建觸發器windows

  這裏我用的是定時任務,通常項目也用的這個選項吧。ui

四、構建環境spa

  這個模塊默認便可,這個示例用不到3d

五、構建

六、構建後操做

  我這裏設置的比較簡單,就是發送郵件。

3、查看構建的結果

  以上設置完成以後,點擊【保存】,點擊左邊菜單欄的【當即構建】,能夠查看構建的結果。

 

  以上,在整個示例過程當中,我遇到了一個坑,說大不大,說小不小。我只能說,windows和Linux仍是區別的,下面來講說這個坑的發生過程:

一、我是windows環境,而後在構建的時候選擇了執行shell腳本,而後改了不少地方,仍是沒解決,報錯方式是這樣的:

[0716_test] $ sh -xe C:\WINDOWS\TEMP\jenkins1910652898694296835.sh
The system cannot find the file specified
FATAL: 命令執行失敗
java.io.IOException: CreateProcess error=2, 系統找不到指定的文件。
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\0716_test"): CreateProcess error=2, 系統找不到指定的文件。
    at java.lang.ProcessBuilder.start(Unknown Source)
    at hudson.Proc$LocalProc.<init>(Proc.java:249)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
    at hudson.Launcher$ProcStarter.start(Launcher.java:449)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1794)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Build step '執行 shell' marked build as failure
Finished: FAILURE

  找了我半個多小時,而後在這裏找到了比較明確的說明以及解決方案:https://stackoverflow.com/questions/30374998/run-a-command-shell-in-jenkins。可是我試了添加系統環境變量和更改Jenkins的shell配置這兩種方法都沒成功,仍是算了,老老實實選擇「執行windows批處理命令」。有興趣的看客能夠試試,成功了給我留個言便可,在此謝過。

補充:針對構建模塊中的語句,此示例中是python xx.py,若是構建以後日誌中提示「python不是內部或者外部命令」。請先在cmd中嘗試執行python的命令(例python,回車。能夠查看Python的版本)看是否成功。報錯的緣由是執行Jenkins的系統用戶環境變量中沒有python的環境變量,因此解決方法是:在系統環境變量path中添加python.exe這個文件的路徑!

 

——日月盈昃,辰宿列張

相關文章
相關標籤/搜索