




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、jenkins執(zhí)行shell讀不到環(huán)境變量問題從系列中,了解到j(luò)enkins執(zhí)行shell的原理。在使用enkins過程中,發(fā)現(xiàn)執(zhí)行shell讀取不到J/etc/profilel以及用戶下.bash_profilei殳置的環(huán)境變量。環(huán)境:RedHatEnterprise5.5根據(jù)jenkins-core項目Shell.java的buildCommandLine方法publicStringbuildCommandLine(FilePathscript)if(commandstartsWith("#!")/interpreteroverrideintend=commandind
2、exOf('n');if(end<0)end=commandlength();List<String>argsnewArrayList<String>();argsaddAll(ArraysasList(Utiltokenize(commandsubstring(0,end).trim();argsadd(scriptgetRemote();argsset(0,argsget(0).substring(2);/trimoff"#!"returnargstoArray(newStringargssize();elsereturnn
3、ewStringgetDescriptor().getShellOrDefault(scriptgetChannel(),"-xe",scriptgetRemote();在默認(rèn)的情況下,執(zhí)行shell會在節(jié)點上tmp目錄生成類似hudson224519953209659762.sh后面數(shù)字根據(jù)規(guī)則生成,具體執(zhí)行的命令如:/bin/sh-xe/tmp/hudson224519953209659762.s。如果ExecuteShell里面具體命令為以下內(nèi)容:#!/bin/bash+x那么根據(jù)上面代碼,具體執(zhí)行的命令就會變成/bin/bash+x/tmp/hudson224519
4、953209659762.sh知道jenkins執(zhí)行shell的原理后,接下來我們要談?wù)劷换ナ胶头墙换ナ絟ell、登錄和非登錄shelI之間的區(qū)別什么是交互式shell(interactiveshell)和非交互式shell(non-interactiveshell)交互式的shell會有一個輸入提示符,并且它的標(biāo)準(zhǔn)輸入、輸出和錯誤輸出都會顯示在控制臺上。這種模式也是大多數(shù)用戶非常熟悉的:登錄、執(zhí)行一些命令、退出。當(dāng)你退出后,shell也終止了。非交互式shell是bashscript.sK這類的shell。在這種模式下,shell不與你進(jìn)行交互,而是讀取存放在文件中的命令并且執(zhí)行它們。當(dāng)它讀
5、到文件的結(jié)尾EOF,shell也就終止了。什么是登錄式shell(loginshell)和非登陸式shell(no-loginshell)需要輸入用戶名和密碼的;hell就是登陸式shell。因此通常不管以何種方式登陸機(jī)器后用戶獲得的第一個hell就是loginshell。不輸入密碼的ssh是公鑰打通的,某種意義上說也是輸入密碼的。非登陸式的就是在登陸后啟動bash等,即不是遠(yuǎn)程登陸到主機(jī)這種。通過manbash了解loginshell和interactiveshell,如下INVOCATIONAloginshellisonewhosefirstcharacterofargumentzeroi
6、sa-,oronestartedwiththe-loginoption.Aninteractiveshellisonestartedwithoutnon-optionargumentsandwithoutthe-coptionwhosestandardinputanderrorarebothconnectedtoterminals(asdeterminedbyisatty(3),oronestartedwiththe-ioption.PS1issetand$-includesiifbashisinteractive,allowingashellscriptorastartupfiletotes
7、tthisstate.Thefollowingparagraphsdescribehowbashexecutesitsstartupfiles.Ifanyofthefilesexistbutcannotberead,bashreportsanerror.TildesareexpandedinfilenamesasdescribedbelowunderTildeExpansionintheEXPANSIONsection.Whenbashisinvokedasaninteractiveloginshell,orasanon-interactiveshellwiththe-loginoption,
8、itfirstreadsandexecutescommandsfromthefile/etc/profile,ifthatfileexists.Afterreadingthatfile,itlooksfor/.bash_profile,/.bash_login,and/.profile,inthatorder,andreadsandexecutescommandsfromthefirstonethatexistsandisreadable.The-noprofileoptionmaybeusedwhentheshellisstartedtoinhibitthisbehavior.Whenalo
9、ginshellexits,bashreadsandexecutescommandsfromthefile/.bash_logout,ifitexists.Whenaninteractiveshellthatisnotaloginshellisstarted,bashreadsandexecutescommandsfrom/.bashrc,ifthatfileexists.Thismaybeinhibitedbyusingthe-norcoption.The-rcfilefileoptionwillforcebashtoreadandexecutecommandsfromfileinstead
10、of/.bashrc.Whenbashisstartednon-interactively,torunashellscript,forexample,itlooksforthevariableBASH_ENVintheenvironment,expandsitsvalueifitappearsthere,andusestheexpandedvalueasthenameofafiletoreadandexecute.Bashbehavesasifthefollowingcommandwereexecuted:if-nH$BASH_ENV"then.H$BASH_ENV"fib
11、utthevalueofthePATHvariableisnotusedtosearchforthefilename.對manbash解讀:如果一個bash是交互式登錄Shell或者使用-login參數(shù)的非交互式Shell。首先會執(zhí)行/etc/profil咬件。然后按順序查按/.bash_profile,/.bash_login,-/.profile,這三個文件誰存在并且有讀權(quán)限就執(zhí)行誰,然后后面的就不會再執(zhí)行??梢酝ㄟ^指定-noprofile參數(shù)來禁止這種默認(rèn)行為。當(dāng)?shù)卿汼hell退出之后,bash會讀取/.bashogou文件并執(zhí)行。如果/.bash_profile文件存在的話,一般還會執(zhí)
12、行/.bashr(文件。因為在/.bash_profile文件中一般會有下面的代碼:if-f/.bashrc;then./.bashrcfi/.bashrc中,一般還會有以下代碼:if-f/etc/bashrc;then./etc/bashrcfi所以執(zhí)行順序為:/etc/profile->(/.bash_profile|/.bash_login|/.profile)->/.bashrc->/etc/bashrc->/.bash_logout如果是一個交互式非登錄Shell,bash會讀取/.bashrc文件。同時,可以指定-norc參數(shù)來禁止該行為,或者通過-rcfi
13、le指定其它文件。如果是一個非交互式非登錄Shell,比如運(yùn)行一個Shell腳本,它會在環(huán)境查找BASH_ENV變量。通過上面的分析,對于常用環(huán)境變量設(shè)置文件,整理出如下加載情況表:文件非交互+登陸式交互+登陸式交互+非登陸式非交互+非登陸式/etc/profile加載加載/etc/bashrc加載加載/.bash_profile加載加載/.bashrc加載加載加載BASH_ENV加載執(zhí)行腳本,女Bbashscript.sS屬于non-login+non-interactive所以jenkins默認(rèn)情況下/bin/sh-xe/tmp/hudson224519953209659762.sh是屬于
14、non-login+non-interactive解決方案通過manbash可知:OPTIONSInadditiontothesingle-charactershelloptionsdocumentedinthedescriptionofthesetbuiltincommand,bashinterpretsthefollowingoptionswhenitisinvoked:-cstringIfthe-coptionispresent,thencommandsarereadfromstring.Ifthereareargumentsafterthestring,theyareassignedt
15、othepositionalparameters,startingwith$0.-iIfthe-ioptionispresent,theshellisinteractive.-lMakebashactasifithadbeeninvokedasaloginshell(seeINVOCATIONbelow).-rIfthe-roptionispresent,theshellbecomesrestricted(seeRESTRICTEDSHELLbelow).-sIfthe-soptionispresent,orifnoargumentsremainafteroptionprocessing,thencommandsarereadfromthestandardinput.Thisoptionallowsthepositionalparameterstobesetwheninvokinganinteractiveshell.-DAlistofalldouble-quotedstringsprecededby$isprintedonthestandardoutput.Thesearethestringsthataresubjecttolanguagetranslationwhe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度企業(yè)財產(chǎn)一切險保險合同范本
- 2025年度購房合同轉(zhuǎn)讓及物業(yè)移交管理服務(wù)協(xié)議
- 2025年度新能源企業(yè)員工聘用創(chuàng)新合同
- 二零二五年度藝人網(wǎng)絡(luò)文學(xué)改編簽約協(xié)議
- 2025年度購房公積金提取合同解除書
- 2025年度智能空調(diào)清洗與節(jié)能改造服務(wù)合同
- 二零二五年度電商直播帶貨渠道代理合作協(xié)議
- 二零二五年度新型環(huán)保材料研發(fā)中心廠房租賃合同終止協(xié)議
- 二零二五年度委托中介出售手房并支持分期付款合同
- 二零二五年度房屋買賣合同定金返還糾紛訴狀
- 高新技術(shù)企業(yè)認(rèn)定申請書樣例與說明
- 數(shù)據(jù)結(jié)構(gòu)英文教學(xué)課件:chapter6 Tree
- 高壓氧科工作總結(jié)高壓氧科個人年終總結(jié).doc
- 《政治學(xué)概論》教學(xué)大綱
- 橋梁缺陷與預(yù)防
- 食品生物化學(xué)習(xí)題謝達(dá)平(動態(tài))
- 新蘇教版小學(xué)科學(xué)三年級下冊全冊教案(2022年春修訂)
- 保安員工入職登記表
- 睿達(dá)RDCAM激光雕刻切割軟件V5.0操作說明書
- 機(jī)械設(shè)計基礎(chǔ)平面連桿機(jī)構(gòu)課件
- 人力資源部經(jīng)理崗位說明書
評論
0/150
提交評論