Tools to make Jenkins jobs from templates
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

publishers.py 294KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218
  1. # Copyright 2012 Hewlett-Packard Development Company, L.P.
  2. # Copyright 2012 Varnish Software AS
  3. # Copyright 2013-2014 Antoine "hashar" Musso
  4. # Copyright 2013-2014 Wikimedia Foundation Inc.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. """
  18. Publishers define actions that the Jenkins job should perform after
  19. the build is complete.
  20. **Component**: publishers
  21. :Macro: publisher
  22. :Entry Point: jenkins_jobs.publishers
  23. """
  24. import logging
  25. import pkg_resources
  26. import sys
  27. import xml.etree.ElementTree as XML
  28. import six
  29. from jenkins_jobs.errors import InvalidAttributeError
  30. from jenkins_jobs.errors import JenkinsJobsException
  31. from jenkins_jobs.errors import MissingAttributeError
  32. import jenkins_jobs.modules.base
  33. from jenkins_jobs.modules import hudson_model
  34. import jenkins_jobs.modules.helpers as helpers
  35. def allure(registry, xml_parent, data):
  36. """yaml: allure
  37. Publish Allure report for the build. Requires the Jenkins
  38. :jenkins-wiki:`Allure Plugin <Allure+Plugin>`.
  39. :arg str jdk: String identifier for a JDK installation in Jenkins
  40. :arg str commandline: String identifier for a Allure-commandline tool
  41. installation
  42. :arg str report-build-policy: String identifier for a report build
  43. policy enum. Possible values: 'ALWAYS', 'UNSTABLE', 'UNSUCCESSFUL'.
  44. (By default is 'ALWAYS')
  45. :arg bool include-properties: Flag to include specified properties
  46. :arg list results-paths: List of results directories
  47. :arg list properties: List of key:value property pairs
  48. Minimal Example:
  49. .. literalinclude::
  50. /../../tests/publishers/fixtures/allure-minimal.yaml
  51. :language: yaml
  52. Full Example:
  53. .. literalinclude:: /../../tests/publishers/fixtures/allure-full.yaml
  54. :language: yaml
  55. """
  56. publisher_class = 'ru.yandex.qatools.allure.jenkins.AllureReportPublisher'
  57. property_class = 'ru.yandex.qatools.allure.jenkins.config.PropertyConfig'
  58. results_class = 'ru.yandex.qatools.allure.jenkins.config.ResultsConfig'
  59. allure_publisher = XML.SubElement(xml_parent, publisher_class)
  60. allure_publisher.set('plugin', 'allure-jenkins-plugin')
  61. config = XML.SubElement(allure_publisher, 'config')
  62. results = XML.SubElement(config, 'results')
  63. if 'results-paths' in data:
  64. for results_path in data['results-paths']:
  65. entry = XML.SubElement(results, results_class)
  66. path = XML.SubElement(entry, 'path')
  67. path.text = results_path['path']
  68. properties = XML.SubElement(config, 'properties')
  69. if 'properties' in data:
  70. property_mapping = [
  71. ('key', 'key', None),
  72. ('value', 'value', None)
  73. ]
  74. for prop in data['properties']:
  75. entry = XML.SubElement(properties, property_class)
  76. helpers.convert_mapping_to_xml(entry, prop, property_mapping,
  77. fail_required=True)
  78. else:
  79. properties.set('class', 'empty-list')
  80. mapping = [
  81. ('jdk', 'jdk', ''),
  82. ('commandline', 'commandline', ''),
  83. ('report-build-policy', 'reportBuildPolicy', 'ALWAYS',
  84. ['ALWAYS', 'UNSTABLE', 'UNSUCCESSFUL']),
  85. ('include-properties', 'includeProperties', False)
  86. ]
  87. helpers.convert_mapping_to_xml(config, data, mapping,
  88. fail_required=True)
  89. def archive(registry, xml_parent, data):
  90. """yaml: archive
  91. Archive build artifacts
  92. :arg str artifacts: path specifier for artifacts to archive
  93. :arg str excludes: path specifier for artifacts to exclude (optional)
  94. :arg bool latest-only: only keep the artifacts from the latest
  95. successful build
  96. :arg bool allow-empty: pass the build if no artifacts are
  97. found (default false)
  98. :arg bool only-if-success: archive artifacts only if build is successful
  99. (default false)
  100. :arg bool fingerprint: fingerprint all archived artifacts (default false)
  101. :arg bool default-excludes: This option allows you to enable or disable the
  102. default Ant exclusions. (default true)
  103. :arg bool case-sensitive: Treat include and exclude patterns as case
  104. sensitive. (default true)
  105. Example:
  106. .. literalinclude:: /../../tests/publishers/fixtures/archive001.yaml
  107. :language: yaml
  108. """
  109. archiver = XML.SubElement(xml_parent, 'hudson.tasks.ArtifactArchiver')
  110. mapping = [
  111. ('artifacts', 'artifacts', None),
  112. ('allow-empty', 'allowEmptyArchive', False),
  113. ('only-if-success', 'onlyIfSuccessful', False),
  114. ('fingerprint', 'fingerprint', False),
  115. ('default-excludes', 'defaultExcludes', True),
  116. ('case-sensitive', 'caseSensitive', True),
  117. ('latest-only', 'latestOnly', False)]
  118. if 'excludes' in data:
  119. mapping.append(('excludes', 'excludes', None))
  120. helpers.convert_mapping_to_xml(archiver, data, mapping, fail_required=True)
  121. def blame_upstream(registry, xml_parent, data):
  122. """yaml: blame-upstream
  123. Notify upstream committers when build fails
  124. Requires the Jenkins :jenkins-wiki:`Blame upstream committers Plugin
  125. <Blame+Upstream+Committers+Plugin>`.
  126. Example:
  127. .. literalinclude:: /../../tests/publishers/fixtures/blame001.yaml
  128. :language: yaml
  129. """
  130. XML.SubElement(xml_parent,
  131. 'hudson.plugins.blame__upstream__commiters.'
  132. 'BlameUpstreamCommitersPublisher')
  133. def jclouds(registry, xml_parent, data):
  134. """yaml: jclouds
  135. JClouds Cloud Storage Settings provides a way to store artifacts on
  136. JClouds supported storage providers. Requires the Jenkins
  137. :jenkins-wiki:`JClouds Plugin <JClouds+Plugin>`.
  138. JClouds Cloud Storage Settings must be configured for the Jenkins instance.
  139. :arg str profile: preconfigured storage profile (required)
  140. :arg str files: files to upload (regex) (required)
  141. :arg str basedir: the source file path (relative to workspace, Optional)
  142. :arg str container: the destination container name (required)
  143. :arg bool hierarchy: keep hierarchy (default false)
  144. Example:
  145. .. literalinclude:: /../../tests/publishers/fixtures/jclouds001.yaml
  146. """
  147. deployer = XML.SubElement(xml_parent,
  148. 'jenkins.plugins.jclouds.blobstore.'
  149. 'BlobStorePublisher')
  150. if 'profile' not in data:
  151. raise JenkinsJobsException('profile parameter is missing')
  152. XML.SubElement(deployer, 'profileName').text = data.get('profile')
  153. entries = XML.SubElement(deployer, 'entries')
  154. deployer_entry = XML.SubElement(entries,
  155. 'jenkins.plugins.jclouds.blobstore.'
  156. 'BlobStoreEntry')
  157. try:
  158. XML.SubElement(deployer_entry, 'container').text = data['container']
  159. XML.SubElement(deployer_entry, 'path').text = data.get('basedir', '')
  160. XML.SubElement(deployer_entry, 'sourceFile').text = data['files']
  161. except KeyError as e:
  162. raise JenkinsJobsException("blobstore requires '%s' to be set"
  163. % e.args[0])
  164. mapping = [('hierarchy', 'keepHierarchy', False)]
  165. helpers.convert_mapping_to_xml(
  166. deployer_entry, data, mapping, fail_required=True)
  167. def javadoc(registry, xml_parent, data):
  168. """yaml: javadoc
  169. Publish Javadoc
  170. Requires the Jenkins :jenkins-wiki:`Javadoc Plugin <Javadoc+Plugin>`.
  171. :arg str directory: Directory relative to the root of the workspace,
  172. such as 'myproject/build/javadoc' (optional)
  173. :arg bool keep-all-successful: When true, it will retain Javadoc for each
  174. successful build. This allows you to browse Javadoc for older builds,
  175. at the expense of additional disk space requirement. If false, it will
  176. only keep the latest Javadoc, so older Javadoc will be overwritten as
  177. new builds succeed. (default false)
  178. Example:
  179. .. literalinclude:: /../../tests/publishers/fixtures/javadoc001.yaml
  180. :language: yaml
  181. """
  182. root = XML.SubElement(xml_parent, 'hudson.tasks.JavadocArchiver')
  183. mapping = [
  184. ('directory', 'javadocDir', None),
  185. ('keep-all-successful', 'keepAll', False),
  186. ]
  187. helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
  188. def jdepend(registry, xml_parent, data):
  189. """yaml: jdepend
  190. Publish jdepend report
  191. Requires the :jenkins-wiki:`JDepend Plugin <JDepend+Plugin>`.
  192. :arg str file: path to jdepend file (required)
  193. Example:
  194. .. literalinclude:: /../../tests/publishers/fixtures/jdepend001.yaml
  195. :language: yaml
  196. """
  197. jdepend = XML.SubElement(
  198. xml_parent,
  199. 'hudson.plugins.jdepend.JDependRecorder')
  200. mapping = [('file', 'configuredJDependFile', None)]
  201. helpers.convert_mapping_to_xml(jdepend, data, mapping, fail_required=True)
  202. def hue_light(registry, xml_parent, data):
  203. """yaml: hue-light
  204. This plugin shows the state of your builds using the awesome Philips hue
  205. lights.
  206. Requires the Jenkins :jenkins-wiki:`hue-light Plugin
  207. <hue-light+Plugin>`.
  208. :arg int light-id: ID of light. Define multiple lights by a comma as a
  209. separator (required)
  210. :arg string pre-build: Colour of building state (default 'blue')
  211. :arg string good-build: Colour of successful state (default 'green')
  212. :arg string unstable-build: Colour of unstable state (default 'yellow')
  213. :arg string bad-build: Colour of unsuccessful state (default 'red')
  214. Full Example:
  215. .. literalinclude::
  216. /../../tests/publishers/fixtures/hue-light-full.yaml
  217. :language: yaml
  218. Minimal Example:
  219. .. literalinclude::
  220. /../../tests/publishers/fixtures/hue-light-minimal.yaml
  221. :language: yaml
  222. """
  223. hue_light = XML.SubElement(
  224. xml_parent, 'org.jenkinsci.plugins.hue__light.LightNotifier')
  225. hue_light.set('plugin', 'hue-light')
  226. lightId = XML.SubElement(hue_light, 'lightId')
  227. id_mapping = [('light-id', 'string', None)]
  228. helpers.convert_mapping_to_xml(
  229. lightId, data, id_mapping, fail_required=True)
  230. build_mapping = [
  231. ('pre-build', 'preBuild', 'blue'),
  232. ('good-build', 'goodBuild', 'green'),
  233. ('unstable-build', 'unstableBuild', 'yellow'),
  234. ('bad-build', 'badBuild', 'red'),
  235. ]
  236. helpers.convert_mapping_to_xml(
  237. hue_light, data, build_mapping, fail_required=True)
  238. def campfire(registry, xml_parent, data):
  239. """yaml: campfire
  240. Send build notifications to Campfire rooms.
  241. Requires the Jenkins :jenkins-wiki:`Campfire Plugin <Campfire+Plugin>`.
  242. Campfire notifications global default values must be configured for
  243. the Jenkins instance. Default values will be used if no specific
  244. values are specified for each job, so all config params are optional.
  245. :arg str subdomain: override the default campfire subdomain
  246. :arg str token: override the default API token
  247. :arg bool ssl: override the default 'use SSL'
  248. :arg str room: override the default room name
  249. Example:
  250. .. literalinclude:: /../../tests/publishers/fixtures/campfire001.yaml
  251. :language: yaml
  252. """
  253. root = XML.SubElement(xml_parent,
  254. 'hudson.plugins.campfire.'
  255. 'CampfireNotifier')
  256. campfire = XML.SubElement(root, 'campfire')
  257. mapping = [
  258. ('subdomain', 'subdomain', None),
  259. ('token', 'token', None),
  260. ('ssl', 'ssl', None),
  261. ]
  262. helpers.convert_mapping_to_xml(
  263. campfire, data, mapping, fail_required=False)
  264. if 'room' in data:
  265. room = XML.SubElement(root, 'room')
  266. mapping = [('room', 'name', None)]
  267. helpers.convert_mapping_to_xml(room, data, mapping, fail_required=True)
  268. XML.SubElement(room, 'campfire reference="../../campfire"')
  269. def mqtt(registry, xml_parent, data):
  270. """yaml: mqtt
  271. This plugin lets you send build notifications to a MQTT message queue.
  272. Requires the :jenkins-wiki:`MQTT Notification Plugin
  273. <MQTT+Notification+Plugin>`.
  274. :arg str broker-url: the broker URL, as protocol://address:port (required)
  275. :arg str credentials-id: credentials to use to connect to the broker
  276. (optional)
  277. :arg str topic: the message topic (default "jenkins/$PROJECT_URL")
  278. :arg str message: the message itself (default "$BUILD_RESULT")
  279. :arg str qos: one of AT_MOST_ONCE, AT_LEAST_ONCE, or EXACTLY_ONCE
  280. (default AT_MOST_ONCE)
  281. :arg bool retain-message: whether to resend message or not when a new
  282. client connects (default false)
  283. Minimal Example:
  284. .. literalinclude:: /../../tests/publishers/fixtures/mqtt-minimal.yaml
  285. :language: yaml
  286. Full Example:
  287. .. literalinclude:: /../../tests/publishers/fixtures/mqtt-full.yaml
  288. :language: yaml
  289. """
  290. mqtt = XML.SubElement(xml_parent,
  291. 'jenkins.plugins.mqttnotification.MqttNotifier')
  292. mqtt.set('plugin', 'mqtt-notification-plugin')
  293. mqtt_mapping = [
  294. ('broker-url', 'brokerUrl', None), ]
  295. helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping,
  296. fail_required=True)
  297. mqtt_mapping = [
  298. ('credentials-id', 'credentialsId', None),
  299. ('topic', 'topic', 'jenkins/$PROJECT_URL'),
  300. ('message', 'message', '$BUILD_RESULT'),
  301. ('qos', 'qos', 'AT_MOST_ONCE', {'AT_MOST_ONCE': '0',
  302. 'AT_LEAST_ONCE': '1',
  303. 'EXACTLY_ONCE': '2'}),
  304. ('retain-message', 'retainMessage', False)
  305. ]
  306. helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping)
  307. def codecover(registry, xml_parent, data):
  308. """yaml: codecover
  309. This plugin allows you to capture code coverage report from CodeCover.
  310. Jenkins will generate the trend report of coverage.
  311. Requires the Jenkins :jenkins-wiki:`CodeCover Plugin <CodeCover+Plugin>`.
  312. :arg str include: Specify the path to the CodeCover HTML report file,
  313. relative to the workspace root (default '')
  314. :arg int min-statement: Minimum statement threshold (default 0)
  315. :arg int max-statement: Maximum statement threshold (default 90)
  316. :arg int min-branch: Minimum branch threshold (default 0)
  317. :arg int max-branch: Maximum branch threshold (default 80)
  318. :arg int min-loop: Minimum loop threshold (default 0)
  319. :arg int max-loop: Maximum loop threshold (default 50)
  320. :arg int min-condition: Minimum condition threshold (default 0)
  321. :arg int max-condition: Maximum conditon threshold (default 50)
  322. Minimal Example:
  323. .. literalinclude::
  324. /../../tests/publishers/fixtures/codecover-minimal.yaml
  325. :language: yaml
  326. Full Example:
  327. .. literalinclude::
  328. /../../tests/publishers/fixtures/codecover-full.yaml
  329. :language: yaml
  330. """
  331. codecover = XML.SubElement(
  332. xml_parent, 'hudson.plugins.codecover.CodeCoverPublisher')
  333. codecover.set('plugin', 'codecover')
  334. XML.SubElement(codecover, 'includes').text = str(data.get('include', ''))
  335. health_report = XML.SubElement(codecover, 'healthReports')
  336. mapping = [
  337. ('min-statement', 'minStatement', 0),
  338. ('max-statement', 'maxStatement', 90),
  339. ('min-branch', 'minBranch', 0),
  340. ('max-branch', 'maxBranch', 80),
  341. ('min-loop', 'minLoop', 0),
  342. ('max-loop', 'maxLoop', 50),
  343. ('min-condition', 'minCondition', 0),
  344. ('max-condition', 'maxCondition', 50),
  345. ]
  346. helpers.convert_mapping_to_xml(
  347. health_report, data, mapping, fail_required=True)
  348. def emotional_jenkins(registry, xml_parent, data):
  349. """yaml: emotional-jenkins
  350. Emotional Jenkins. This funny plugin changes the expression of Mr. Jenkins
  351. in the background when your builds fail.
  352. Requires the Jenkins :jenkins-wiki:`Emotional Jenkins Plugin
  353. <Emotional+Jenkins+Plugin>`.
  354. Example:
  355. .. literalinclude::
  356. /../../tests/publishers/fixtures/emotional-jenkins.yaml
  357. :language: yaml
  358. """
  359. XML.SubElement(xml_parent,
  360. 'org.jenkinsci.plugins.emotional__jenkins.'
  361. 'EmotionalJenkinsPublisher')
  362. def trigger_parameterized_builds(registry, xml_parent, data):
  363. """yaml: trigger-parameterized-builds
  364. Trigger parameterized builds of other jobs.
  365. Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin
  366. <Parameterized+Trigger+Plugin>`.
  367. Use of the `node-label-name` or `node-label` parameters
  368. requires the Jenkins :jenkins-wiki:`NodeLabel Parameter Plugin
  369. <NodeLabel+Parameter+Plugin>`.
  370. Note: 'node-parameters' overrides the Node that the triggered
  371. project is tied to.
  372. :arg list project: list the jobs to trigger, will generate comma-separated
  373. string containing the named jobs.
  374. :arg str predefined-parameters: parameters to pass to the other
  375. job (optional)
  376. :arg bool current-parameters: Whether to include the parameters passed
  377. to the current build to the triggered job (optional)
  378. :arg bool node-parameters: Use the same Node for the triggered builds
  379. that was used for this build. (optional)
  380. :arg bool svn-revision: Pass svn revision to the triggered job (optional)
  381. :arg bool include-upstream: Include/pass through Upstream SVN Revisons.
  382. Only valid when 'svn-revision' is true. (default false)
  383. :arg dict git-revision: Passes git revision to the triggered job
  384. (optional).
  385. * **combine-queued-commits** (bool): Whether to combine queued git
  386. hashes or not (default false)
  387. :arg bool combine-queued-commits: Combine Queued git hashes. Only valid
  388. when 'git-revision' is true. (default false)
  389. .. deprecated:: 1.5.0 Please use `combine-queued-commits` under the
  390. `git-revision` argument instead.
  391. :arg dict boolean-parameters: Pass boolean parameters to the downstream
  392. jobs. Specify the name and boolean value mapping of the parameters.
  393. (optional)
  394. :arg str condition: when to trigger the other job. Can be: 'SUCCESS',
  395. 'UNSTABLE', 'FAILED_OR_BETTER', 'UNSTABLE_OR_BETTER',
  396. 'UNSTABLE_OR_WORSE', 'FAILED', 'ALWAYS'. (default 'ALWAYS')
  397. :arg str property-file: Use properties from file (optional)
  398. :arg bool fail-on-missing: Blocks the triggering of the downstream jobs
  399. if any of the property files are not found in the workspace.
  400. Only valid when 'property-file' is specified.
  401. (default 'False')
  402. :arg bool use-matrix-child-files: Use files in workspaces of child
  403. builds (default 'False')
  404. :arg str matrix-child-combination-filter: A Groovy expression to filter
  405. the child builds to look in for files
  406. :arg bool only-exact-matrix-child-runs: Use only child builds triggered
  407. exactly by the parent.
  408. :arg str file-encoding: Encoding of contents of the files. If not
  409. specified, default encoding of the platform is used. Only valid when
  410. 'property-file' is specified. (optional)
  411. :arg bool trigger-with-no-params: Trigger a build even when there are
  412. currently no parameters defined (default 'False')
  413. :arg str restrict-matrix-project: Filter that restricts the subset
  414. of the combinations that the downstream project will run (optional)
  415. :arg str node-label-name: Specify the Name for the NodeLabel parameter.
  416. (optional)
  417. :arg str node-label: Specify the Node for the NodeLabel parameter.
  418. (optional)
  419. Example:
  420. .. literalinclude::
  421. /../../tests/publishers/fixtures/trigger_parameterized_builds001.yaml
  422. :language: yaml
  423. .. literalinclude::
  424. /../../tests/publishers/fixtures/trigger_parameterized_builds003.yaml
  425. :language: yaml
  426. """
  427. pt_prefix = 'hudson.plugins.parameterizedtrigger.'
  428. tbuilder = XML.SubElement(xml_parent, pt_prefix + 'BuildTrigger')
  429. configs = XML.SubElement(tbuilder, 'configs')
  430. param_order = helpers.trigger_get_parameter_order(
  431. registry, 'trigger-parameterized-builds')
  432. for project_def in data:
  433. tconfig = XML.SubElement(configs, pt_prefix + 'BuildTriggerConfig')
  434. tconfigs = XML.SubElement(tconfig, 'configs')
  435. helpers.trigger_project(tconfigs, project_def, param_order)
  436. if not list(tconfigs):
  437. # no child parameter tags added
  438. tconfigs.set('class', 'java.util.Collections$EmptyList')
  439. projects = XML.SubElement(tconfig, 'projects')
  440. if isinstance(project_def['project'], list):
  441. projects.text = ",".join(project_def['project'])
  442. else:
  443. projects.text = project_def['project']
  444. condition = XML.SubElement(tconfig, 'condition')
  445. condition.text = project_def.get('condition', 'ALWAYS')
  446. trigger_with_no_params = XML.SubElement(tconfig,
  447. 'triggerWithNoParameters')
  448. trigger_with_no_params.text = str(
  449. project_def.get('trigger-with-no-params', False)).lower()
  450. def trigger(registry, xml_parent, data):
  451. """yaml: trigger
  452. Trigger non-parametrised builds of other jobs.
  453. :arg str project: name of the job to trigger
  454. :arg str threshold: when to trigger the other job (default 'SUCCESS'),
  455. alternatives: SUCCESS, UNSTABLE, FAILURE
  456. Example:
  457. .. literalinclude:: /../../tests/publishers/fixtures/trigger_success.yaml
  458. :language: yaml
  459. """
  460. tconfig = XML.SubElement(xml_parent, 'hudson.tasks.BuildTrigger')
  461. childProjects = XML.SubElement(tconfig, 'childProjects')
  462. childProjects.text = data['project']
  463. tthreshold = XML.SubElement(tconfig, 'threshold')
  464. threshold = data.get('threshold', 'SUCCESS')
  465. supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
  466. if threshold not in supported_thresholds:
  467. raise JenkinsJobsException("threshold must be one of %s" %
  468. ", ".join(supported_thresholds))
  469. tname = XML.SubElement(tthreshold, 'name')
  470. tname.text = hudson_model.THRESHOLDS[threshold]['name']
  471. tordinal = XML.SubElement(tthreshold, 'ordinal')
  472. tordinal.text = hudson_model.THRESHOLDS[threshold]['ordinal']
  473. tcolor = XML.SubElement(tthreshold, 'color')
  474. tcolor.text = hudson_model.THRESHOLDS[threshold]['color']
  475. def clone_workspace(registry, xml_parent, data):
  476. """yaml: clone-workspace
  477. Archive the workspace from builds of one project and reuse them as the SCM
  478. source for another project.
  479. Requires the Jenkins :jenkins-wiki:`Clone Workspace SCM Plugin
  480. <Clone+Workspace+SCM+Plugin>`.
  481. :arg str workspace-glob: Files to include in cloned workspace (default '')
  482. :arg str workspace-exclude-glob: Files to exclude from cloned workspace
  483. :arg str criteria: Criteria for build to be archived. Can be 'any',
  484. 'not failed', or 'successful'. (default 'any')
  485. :arg str archive-method: Choose the method to use for archiving the
  486. workspace. Can be 'tar' or 'zip'. (default 'tar')
  487. :arg bool override-default-excludes: Override default ant excludes.
  488. (default false)
  489. Minimal example:
  490. .. literalinclude::
  491. /../../tests/publishers/fixtures/clone-workspace001.yaml
  492. :language: yaml
  493. Full example:
  494. .. literalinclude::
  495. /../../tests/publishers/fixtures/clone-workspace002.yaml
  496. :language: yaml
  497. """
  498. cloneworkspace = XML.SubElement(
  499. xml_parent,
  500. 'hudson.plugins.cloneworkspace.CloneWorkspacePublisher')
  501. cloneworkspace.set('plugin', 'clone-workspace-scm')
  502. mappings = [
  503. ('workspace-glob', 'workspaceGlob', ''),
  504. ('override-default-excludes', 'overrideDefaultExcludes', False),
  505. ]
  506. helpers.convert_mapping_to_xml(
  507. cloneworkspace, data, mappings, fail_required=True)
  508. if 'workspace-exclude-glob' in data:
  509. XML.SubElement(
  510. cloneworkspace,
  511. 'workspaceExcludeGlob').text = data['workspace-exclude-glob']
  512. criteria_list = ['Any', 'Not Failed', 'Successful']
  513. criteria = data.get('criteria', 'Any').title()
  514. if 'criteria' in data and criteria not in criteria_list:
  515. raise JenkinsJobsException(
  516. 'clone-workspace criteria must be one of: '
  517. + ', '.join(criteria_list))
  518. else:
  519. XML.SubElement(cloneworkspace, 'criteria').text = criteria
  520. archive_list = ['TAR', 'ZIP']
  521. archive_method = data.get('archive-method', 'TAR').upper()
  522. if 'archive-method' in data and archive_method not in archive_list:
  523. raise JenkinsJobsException(
  524. 'clone-workspace archive-method must be one of: '
  525. + ', '.join(archive_list))
  526. else:
  527. XML.SubElement(cloneworkspace, 'archiveMethod').text = archive_method
  528. def cloverphp(registry, xml_parent, data):
  529. """yaml: cloverphp
  530. Capture code coverage reports from PHPUnit
  531. Requires the Jenkins :jenkins-wiki:`Clover PHP Plugin <Clover+PHP+Plugin>`.
  532. Your job definition should pass to PHPUnit the --coverage-clover option
  533. pointing to a file in the workspace (ex: clover-coverage.xml). The filename
  534. has to be filled in the `xml-location` field.
  535. :arg str xml-location: Path to the coverage XML file generated by PHPUnit
  536. using --coverage-clover. Relative to workspace. (required)
  537. :arg dict html: When existent, whether the plugin should generate a HTML
  538. report. Note that PHPUnit already provide a HTML report via its
  539. --cover-html option which can be set in your builder (optional):
  540. * **dir** (str): Directory where HTML report will be generated relative
  541. to workspace. (required in `html` dict).
  542. * **archive** (bool): Whether to archive HTML reports (default true).
  543. :arg list metric-targets: List of metric targets to reach, must be one of
  544. **healthy**, **unhealthy** and **failing**. Each metric target can
  545. takes two parameters:
  546. * **method** Target for method coverage
  547. * **statement** Target for statements coverage
  548. Whenever a metric target is not filled in, the Jenkins plugin can fill
  549. in defaults for you (as of v0.3.3 of the plugin the healthy target will
  550. have method: 70 and statement: 80 if both are left empty). Jenkins Job
  551. Builder will mimic that feature to ensure clean configuration diff.
  552. Minimal example:
  553. .. literalinclude:: /../../tests/publishers/fixtures/cloverphp001.yaml
  554. :language: yaml
  555. Full example:
  556. .. literalinclude:: /../../tests/publishers/fixtures/cloverphp002.yaml
  557. :language: yaml
  558. """
  559. cloverphp = XML.SubElement(
  560. xml_parent,
  561. 'org.jenkinsci.plugins.cloverphp.CloverPHPPublisher')
  562. cloverphp.set('plugin', 'cloverphp')
  563. # The plugin requires clover XML file to parse
  564. if 'xml-location' not in data:
  565. raise JenkinsJobsException('xml-location must be set')
  566. # Whether HTML publishing has been checked
  567. html_publish = False
  568. # By default, disableArchiving = false. Note that we use
  569. # reversed logic.
  570. html_archive = True
  571. if 'html' in data:
  572. html_publish = True
  573. html_dir = data['html'].get('dir', None)
  574. html_archive = data['html'].get('archive', html_archive)
  575. if html_dir is None:
  576. # No point in going further, the plugin would not work
  577. raise JenkinsJobsException('htmldir is required in a html block')
  578. XML.SubElement(cloverphp, 'publishHtmlReport').text = str(
  579. html_publish).lower()
  580. if html_publish:
  581. XML.SubElement(cloverphp, 'reportDir').text = html_dir
  582. XML.SubElement(cloverphp, 'xmlLocation').text = data.get('xml-location')
  583. XML.SubElement(cloverphp, 'disableArchiving').text = str(
  584. not html_archive).lower()
  585. # Handle targets
  586. # Plugin v0.3.3 will fill defaults for us whenever healthy targets are both
  587. # blanks.
  588. default_metrics = {
  589. 'healthy': {'method': 70, 'statement': 80}
  590. }
  591. allowed_metrics = ['healthy', 'unhealthy', 'failing']
  592. metrics = data.get('metric-targets', [])
  593. # list of dicts to dict
  594. metrics = dict(kv for m in metrics for kv in m.items())
  595. # Populate defaults whenever nothing has been filled by user.
  596. for default in default_metrics.keys():
  597. if metrics.get(default, None) is None:
  598. metrics[default] = default_metrics[default]
  599. # The plugin would at least define empty targets so make sure
  600. # we output them all in the XML regardless of what the user
  601. # has or has not entered.
  602. for target in allowed_metrics:
  603. cur_target = XML.SubElement(cloverphp, target + 'Target')
  604. for t_type in ['method', 'statement']:
  605. val = metrics.get(target, {}).get(t_type)
  606. if val is None or type(val) != int:
  607. continue
  608. if val < 0 or val > 100:
  609. raise JenkinsJobsException(
  610. "Publisher cloverphp metric target %s:%s = %s "
  611. "is not in valid range 0-100." % (target, t_type, val))
  612. XML.SubElement(cur_target, t_type + 'Coverage').text = str(val)
  613. def coverage(registry, xml_parent, data):
  614. """yaml: coverage
  615. WARNING: The coverage function is deprecated. Instead, use the
  616. cobertura function to generate a cobertura coverage report.
  617. Requires the Jenkins :jenkins-wiki:`Cobertura Coverage Plugin
  618. <Cobertura+Plugin>`.
  619. Example:
  620. .. literalinclude:: /../../tests/publishers/fixtures/coverage001.yaml
  621. :language: yaml
  622. """
  623. logger = logging.getLogger(__name__)
  624. logger.warning("Coverage function is deprecated. Switch to cobertura.")
  625. cobertura = XML.SubElement(xml_parent,
  626. 'hudson.plugins.cobertura.CoberturaPublisher')
  627. XML.SubElement(cobertura, 'coberturaReportFile').text = '**/coverage.xml'
  628. XML.SubElement(cobertura, 'onlyStable').text = 'false'
  629. healthy = XML.SubElement(cobertura, 'healthyTarget')
  630. targets = XML.SubElement(healthy, 'targets', {
  631. 'class': 'enum-map',
  632. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  633. entry = XML.SubElement(targets, 'entry')
  634. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  635. ).text = 'CONDITIONAL'
  636. XML.SubElement(entry, 'int').text = '70'
  637. entry = XML.SubElement(targets, 'entry')
  638. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  639. ).text = 'LINE'
  640. XML.SubElement(entry, 'int').text = '80'
  641. entry = XML.SubElement(targets, 'entry')
  642. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  643. ).text = 'METHOD'
  644. XML.SubElement(entry, 'int').text = '80'
  645. unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
  646. targets = XML.SubElement(unhealthy, 'targets', {
  647. 'class': 'enum-map',
  648. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  649. entry = XML.SubElement(targets, 'entry')
  650. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  651. ).text = 'CONDITIONAL'
  652. XML.SubElement(entry, 'int').text = '0'
  653. entry = XML.SubElement(targets, 'entry')
  654. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  655. ).text = 'LINE'
  656. XML.SubElement(entry, 'int').text = '0'
  657. entry = XML.SubElement(targets, 'entry')
  658. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  659. ).text = 'METHOD'
  660. XML.SubElement(entry, 'int').text = '0'
  661. failing = XML.SubElement(cobertura, 'failingTarget')
  662. targets = XML.SubElement(failing, 'targets', {
  663. 'class': 'enum-map',
  664. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  665. entry = XML.SubElement(targets, 'entry')
  666. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  667. ).text = 'CONDITIONAL'
  668. XML.SubElement(entry, 'int').text = '0'
  669. entry = XML.SubElement(targets, 'entry')
  670. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  671. ).text = 'LINE'
  672. XML.SubElement(entry, 'int').text = '0'
  673. entry = XML.SubElement(targets, 'entry')
  674. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
  675. ).text = 'METHOD'
  676. XML.SubElement(entry, 'int').text = '0'
  677. XML.SubElement(cobertura, 'sourceEncoding').text = 'ASCII'
  678. def cobertura(registry, xml_parent, data):
  679. """yaml: cobertura
  680. Generate a cobertura coverage report.
  681. Requires the Jenkins :jenkins-wiki:`Cobertura Coverage Plugin
  682. <Cobertura+Plugin>`.
  683. :arg str report-file: This is a file name pattern that can be used
  684. to locate the cobertura xml report files (optional)
  685. :arg bool only-stable: Include only stable builds (default false)
  686. :arg bool fail-no-reports: fail builds if no coverage reports are found
  687. (default false)
  688. :arg bool fail-unhealthy: Unhealthy projects will be failed (default false)
  689. :arg bool fail-unstable: Unstable projects will be failed (default false)
  690. :arg bool health-auto-update: Auto update threshold for health on
  691. successful build (default false)
  692. :arg bool stability-auto-update: Auto update threshold for stability on
  693. successful build (default false)
  694. :arg bool zoom-coverage-chart: Zoom the coverage chart and crop area below
  695. the minimum and above the maximum coverage of the past reports
  696. (default false)
  697. :arg str source-encoding: Override the source encoding (default ASCII)
  698. :arg dict targets:
  699. :targets: (packages, files, classes, method, line, conditional)
  700. * **healthy** (`int`): Healthy threshold (default 0)
  701. * **unhealthy** (`int`): Unhealthy threshold (default 0)
  702. * **failing** (`int`): Failing threshold (default 0)
  703. Example:
  704. .. literalinclude:: /../../tests/publishers/fixtures/cobertura001.yaml
  705. :language: yaml
  706. """
  707. cobertura = XML.SubElement(xml_parent,
  708. 'hudson.plugins.cobertura.CoberturaPublisher')
  709. mapping = [
  710. ('report-file', 'coberturaReportFile', '**/coverage.xml'),
  711. ('only-stable', 'onlyStable', False),
  712. ('fail-unhealthy', 'failUnhealthy', False),
  713. ('fail-unstable', 'failUnstable', False),
  714. ('health-auto-update', 'autoUpdateHealth', False),
  715. ('stability-auto-update', 'autoUpdateStability', False),
  716. ('zoom-coverage-chart', 'zoomCoverageChart', False),
  717. ('fail-no-reports', 'failNoReports', False),
  718. ]
  719. helpers.convert_mapping_to_xml(
  720. cobertura, data, mapping, fail_required=True)
  721. healthy = XML.SubElement(cobertura, 'healthyTarget')
  722. targets = XML.SubElement(healthy, 'targets', {
  723. 'class': 'enum-map',
  724. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  725. for item in data['targets']:
  726. item_name = next(iter(item.keys()))
  727. item_values = item.get(item_name, 0)
  728. entry = XML.SubElement(targets, 'entry')
  729. XML.SubElement(entry,
  730. 'hudson.plugins.cobertura.targets.'
  731. 'CoverageMetric').text = str(item_name).upper()
  732. XML.SubElement(entry, 'int').text = str(item_values.get('healthy', 0))
  733. unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
  734. targets = XML.SubElement(unhealthy, 'targets', {
  735. 'class': 'enum-map',
  736. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  737. for item in data['targets']:
  738. item_name = next(iter(item.keys()))
  739. item_values = item.get(item_name, 0)
  740. entry = XML.SubElement(targets, 'entry')
  741. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
  742. 'CoverageMetric').text = str(item_name).upper()
  743. XML.SubElement(entry, 'int').text = str(item_values.get('unhealthy',
  744. 0))
  745. failing = XML.SubElement(cobertura, 'failingTarget')
  746. targets = XML.SubElement(failing, 'targets', {
  747. 'class': 'enum-map',
  748. 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
  749. for item in data['targets']:
  750. item_name = next(iter(item.keys()))
  751. item_values = item.get(item_name, 0)
  752. entry = XML.SubElement(targets, 'entry')
  753. XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
  754. 'CoverageMetric').text = str(item_name).upper()
  755. XML.SubElement(entry, 'int').text = str(item_values.get('failing', 0))
  756. XML.SubElement(cobertura, 'sourceEncoding').text = data.get(
  757. 'source-encoding', 'ASCII')
  758. def jacoco(registry, xml_parent, data):
  759. """yaml: jacoco
  760. Generate a JaCoCo coverage report.
  761. Requires the Jenkins :jenkins-wiki:`JaCoCo Plugin <JaCoCo+Plugin>`.
  762. :arg str exec-pattern: This is a file name pattern that can be used to
  763. locate the jacoco report files (default ``**/**.exec``)
  764. :arg str class-pattern: This is a file name pattern that can be used
  765. to locate class files (default ``**/classes``)
  766. :arg str source-pattern: This is a file name pattern that can be used
  767. to locate source files (default ``**/src/main/java``)
  768. :arg bool update-build-status: Update the build according to the results
  769. (default false)
  770. :arg str inclusion-pattern: This is a file name pattern that can be used
  771. to include certain class files (default '')
  772. :arg str exclusion-pattern: This is a file name pattern that can be used
  773. to exclude certain class files (default '')
  774. :arg dict targets:
  775. :targets: (instruction, branch, complexity, line, method, class)
  776. * **healthy** (`int`): Healthy threshold (default 0)
  777. * **unhealthy** (`int`): Unhealthy threshold (default 0)
  778. Minimal Example:
  779. .. literalinclude:: /../../tests/publishers/fixtures/jacoco-minimal.yaml
  780. :language: yaml
  781. Full Example:
  782. .. literalinclude:: /../../tests/publishers/fixtures/jacoco-full.yaml
  783. :language: yaml
  784. """
  785. jacoco = XML.SubElement(xml_parent,
  786. 'hudson.plugins.jacoco.JacocoPublisher')
  787. jacoco.set('plugin', 'jacoco')
  788. mappings = [
  789. ('exec-pattern', 'execPattern', '**/**.exec'),
  790. ('class-pattern', 'classPattern', '**/classes'),
  791. ('source-pattern', 'sourcePattern', '**/src/main/java'),
  792. ('update-build-status', 'changeBuildStatus', False),
  793. ('inclusion-pattern', 'inclusionPattern', ''),
  794. ('exclusion-pattern', 'exclusionPattern', ''),
  795. ]
  796. helpers.convert_mapping_to_xml(jacoco, data, mappings, fail_required=True)
  797. itemsList = ['instruction',
  798. 'branch',
  799. 'complexity',
  800. 'line',
  801. 'method',
  802. 'class']
  803. if 'targets' in data:
  804. for item in data['targets']:
  805. item_name = next(iter(item.keys()))
  806. if item_name not in itemsList:
  807. raise InvalidAttributeError('targets', item_name, itemsList)
  808. item_values = item[item_name]
  809. if item_values:
  810. XML.SubElement(jacoco,
  811. 'maximum' +
  812. item_name.capitalize() +
  813. 'Coverage').text = str(
  814. item_values.get('healthy', 0))
  815. XML.SubElement(jacoco,
  816. 'minimum' +
  817. item_name.capitalize() +
  818. 'Coverage').text = str(
  819. item_values.get('unhealthy', 0))
  820. else:
  821. raise MissingAttributeError(
  822. ['healthy', 'unhealthy'],
  823. 'publishers.jacoco.targets.' + item_name)
  824. def ftp(registry, xml_parent, data):
  825. """yaml: ftp
  826. Upload files via FTP.
  827. Requires the Jenkins :jenkins-wiki:`Publish over FTP Plugin
  828. <Publish+Over+FTP+Plugin>`.
  829. :arg str site: name of the ftp site
  830. :arg str target: destination directory
  831. :arg bool target-is-date-format: whether target is a date format. If true,
  832. raw text should be quoted (default false)
  833. :arg bool clean-remote: should the remote directory be deleted before
  834. transferring files (default false)
  835. :arg str source: source path specifier
  836. :arg str excludes: excluded file pattern (optional)
  837. :arg str remove-prefix: prefix to remove from uploaded file paths
  838. (optional)
  839. :arg bool fail-on-error: fail the build if an error occurs (default false).
  840. :arg bool flatten: only create files on the server, don't create
  841. directories (default false).
  842. Example:
  843. .. literalinclude:: /../../tests/publishers/fixtures/ftp001.yaml
  844. :language: yaml
  845. """
  846. console_prefix = 'FTP: '
  847. plugin_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisherPlugin'
  848. publisher_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisher'
  849. transfer_tag = 'jenkins.plugins.publish__over__ftp.BapFtpTransfer'
  850. plugin_reference_tag = 'jenkins.plugins.publish_over_ftp.' \
  851. 'BapFtpPublisherPlugin'
  852. (_, transfer_node) = base_publish_over(xml_parent,
  853. data,
  854. console_prefix,
  855. plugin_tag,
  856. publisher_tag,
  857. transfer_tag,
  858. plugin_reference_tag)
  859. mapping = [('', 'asciiMode', 'false')]
  860. helpers.convert_mapping_to_xml(
  861. transfer_node, data, mapping, fail_required=True)
  862. def ftp_publisher(registry, xml_parent, data):
  863. """yaml: ftp-publisher
  864. This plugin can be used to upload project artifacts and whole directories
  865. to an ftp server.
  866. Requires the Jenkins :jenkins-wiki:`FTP-Publisher Plugin
  867. <FTP-Publisher+Plugin>`.
  868. :arg list uploads: List of files to upload
  869. :uploads:
  870. * **file-path** ('str') -- Destination folder. It will be created
  871. if doesn't exists. Created relative to ftp root directory.
  872. (default '')
  873. * **source-file** ('str') -- Source files which will be uploaded
  874. (default '')
  875. :arg str site-name: Name of FTP server to upload to (required)
  876. :arg bool use-timestamps: Use timestamps in the FTP directory path (default
  877. false)
  878. :arg bool flatten-files: Flatten files on the FTP host (default false)
  879. :arg bool skip-publishing: Skip publishing (default false)
  880. Minimal Example:
  881. .. literalinclude::
  882. /../../tests/publishers/fixtures/ftp-publisher-minimal.yaml
  883. :language: yaml
  884. Full Example:
  885. .. literalinclude::
  886. /../../tests/publishers/fixtures/ftp-publisher-full.yaml
  887. :language: yaml
  888. """
  889. ftp = XML.SubElement(xml_parent, 'com.zanox.hudson.plugins.FTPPublisher')
  890. ftp.set('plugin', 'ftppublisher')
  891. entries = XML.SubElement(ftp, 'entries')
  892. if 'uploads' in data:
  893. upload_mapping = [
  894. ('file-path', 'filePath', ''),
  895. ('source-file', 'sourceFile', ''),
  896. ]
  897. for upload in data['uploads']:
  898. entry = XML.SubElement(entries, 'com.zanox.hudson.plugins.Entry')
  899. helpers.convert_mapping_to_xml(
  900. entry, upload, upload_mapping, fail_required=True)
  901. mapping = [
  902. ('site-name', 'siteName', None),
  903. ('use-timestamps', 'useTimestamps', False),
  904. ('flatten-files', 'flatten', False),
  905. ('skip-publishing', 'skip', False),
  906. ]
  907. helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True)
  908. def junit(registry, xml_parent, data):
  909. """yaml: junit
  910. Publish JUnit test results.
  911. :arg str results: results filename (required)
  912. :arg bool keep-long-stdio: Retain long standard output/error in test
  913. results (default true).
  914. :arg float health-scale-factor: Amplification factor to apply to test
  915. failures when computing the test result contribution to the build
  916. health score. (default 1.0)
  917. :arg bool allow-empty-results: Do not fail the build on empty test results
  918. (default false)
  919. :arg bool test-stability: Add historical information about test
  920. results stability (default false).
  921. Requires the Jenkins :jenkins-wiki:`Test stability Plugin
  922. <Test+stability+plugin>`.
  923. :arg bool claim-build: Allow claiming of failed tests (default false)
  924. Requires the Jenkins :jenkins-wiki:`Claim Plugin <Claim+plugin>`.
  925. :arg bool measurement-plots: Create measurement plots (default false)
  926. Requires the Jenkins :jenkins-wiki:`Measurement Plots Plugin
  927. <Measurement+Plots+Plugin>`.
  928. :arg bool flaky-test-reports: Publish flaky test reports (default false).
  929. Requires the Jenkins :jenkins-wiki:`Flaky Test Handler Plugin
  930. <Flaky+Test+Handler+Plugin>`.
  931. :arg bool junit-attachments: Publish test attachments (default false).
  932. Requires the Jenkins :jenkins-wiki:`JUnit Attachments Plugin
  933. <JUnit+Attachments+Plugin>`.
  934. Minimal example using defaults:
  935. .. literalinclude:: /../../tests/publishers/fixtures/junit001.yaml
  936. :language: yaml
  937. Full example:
  938. .. literalinclude:: /../../tests/publishers/fixtures/junit002.yaml
  939. :language: yaml
  940. """
  941. junitresult = XML.SubElement(xml_parent,
  942. 'hudson.tasks.junit.JUnitResultArchiver')
  943. junitresult.set('plugin', 'junit')
  944. mapping = [
  945. ('results', 'testResults', None),
  946. ('keep-long-stdio', 'keepLongStdio', True),
  947. ('health-scale-factor', 'healthScaleFactor', '1.0'),
  948. ('allow-empty-results', 'allowEmptyResults', False),
  949. ]
  950. helpers.convert_mapping_to_xml(
  951. junitresult, data, mapping, fail_required=True)
  952. datapublisher = XML.SubElement(junitresult, 'testDataPublishers')
  953. if str(data.get('test-stability', False)).lower() == 'true':
  954. XML.SubElement(datapublisher,
  955. 'de.esailors.jenkins.teststability'
  956. '.StabilityTestDataPublisher')
  957. if str(data.get('claim-build', False)).lower() == 'true':
  958. XML.SubElement(datapublisher,
  959. 'hudson.plugins.claim.ClaimTestDataPublisher')
  960. if str(data.get('measurement-plots', False)).lower() == 'true':
  961. XML.SubElement(datapublisher,
  962. 'hudson.plugins.measurement__plots.TestDataPublisher')
  963. if str(data.get('flaky-test-reports', False)).lower() == 'true':
  964. XML.SubElement(datapublisher,
  965. 'com.google.jenkins.flakyTestHandler.plugin'
  966. '.JUnitFlakyTestDataPublisher')
  967. if str(data.get('junit-attachments', False)).lower() == 'true':
  968. XML.SubElement(datapublisher,
  969. 'hudson.plugins.junitattachments.AttachmentPublisher')
  970. def cucumber_reports(registry, xml_parent, data):
  971. """yaml: cucumber-reports
  972. This plugin creates pretty cucumber-jvm html reports on jenkins.
  973. Requires the Jenkins :jenkins-wiki:`cucumber reports
  974. <Cucumber+Reports+Plugin>`.
  975. :arg str json-reports-path: The path relative to the workspace of
  976. the json reports generated by cucumber-jvm e.g. target - leave
  977. empty to scan the whole workspace (default '')
  978. :arg str file-include-pattern: Include pattern (default '')
  979. :arg str file-exclude-pattern: Exclude pattern (default '')
  980. :arg str plugin-url-path: The path to the jenkins user content url
  981. e.g. :samp:`http://host:port[/jenkins/]plugin` - leave empty if jenkins
  982. url root is host:port (default '')
  983. :arg bool skipped-fails: Skipped steps to cause the build to fail
  984. (default false)
  985. :arg bool pending-fails: Pending steps to cause the build to fail
  986. (default false)
  987. :arg bool undefined-fails: Undefined steps to cause the build to fail
  988. (default false)
  989. :arg bool missing-fails: Missing steps to cause the build to fail
  990. (default false)
  991. :arg bool no-flash-charts: Use javascript charts instead of flash charts
  992. (default false)
  993. :arg bool ignore-failed-tests: Entire build to fail when these tests fail
  994. (default false)
  995. :arg bool parallel-testing: Run same test in parallel for multiple devices
  996. (default false)
  997. Full example:
  998. .. literalinclude::
  999. /../../tests/publishers/fixtures/cucumber-reports-full.yaml
  1000. :language: yaml
  1001. Minimal Example:
  1002. .. literalinclude::
  1003. /../../tests/publishers/fixtures/cucumber-reports-minimal.yaml
  1004. :language: yaml
  1005. """
  1006. cucumber_reports = XML.SubElement(xml_parent,
  1007. 'net.masterthought.jenkins.'
  1008. 'CucumberReportPublisher')
  1009. cucumber_reports.set('plugin', 'cucumber-reports')
  1010. mappings = [
  1011. ('json-reports-path', 'jsonReportDirectory', ''),
  1012. ('plugin-url-path', 'pluginUrlPath', ''),
  1013. ('file-include-pattern', 'fileIncludePattern', ''),
  1014. ('file-exclude-pattern', 'fileExcludePattern', ''),
  1015. ('skipped-fails', 'skippedFails', False),
  1016. ('pending-fails', 'pendingFails', False),
  1017. ('undefined-fails', 'undefinedFails', False),
  1018. ('missing-fails', 'missingFails', False),
  1019. ('no-flash-charts', 'noFlashCharts', False),
  1020. ('ignore-failed-tests', 'ignoreFailedTests', False),
  1021. ('parallel-testing', 'parallelTesting', False)
  1022. ]
  1023. helpers.convert_mapping_to_xml(
  1024. cucumber_reports, data, mappings, fail_required=True)
  1025. def cucumber_testresult(registry, xml_parent, data):
  1026. """yaml: cucumber-testresult
  1027. Publish cucumber test results.
  1028. Requires the Jenkins :jenkins-wiki:`cucumber testresult
  1029. <Cucumber+Test+Result+Plugin>`.
  1030. :arg str results: Results filename (required)
  1031. :arg bool ignore-bad-steps: Ignore not existed step results (default false)
  1032. Minimal example:
  1033. .. literalinclude::
  1034. /../../tests/publishers/fixtures/cucumber-testresult-minimal.yaml
  1035. :language: yaml
  1036. Full Example:
  1037. .. literalinclude::
  1038. /../../tests/publishers/fixtures/cucumber-testresult-full.yaml
  1039. :language: yaml
  1040. """
  1041. cucumber_result = XML.SubElement(xml_parent,
  1042. 'org.jenkinsci.plugins.cucumber.'
  1043. 'jsontestsupport.'
  1044. 'CucumberTestResultArchiver')
  1045. cucumber_result.set('plugin', 'cucumber-testresult-plugin')
  1046. mappings = [
  1047. ('results', 'testResults', None),
  1048. ('ignore-bad-steps', 'ignoreBadSteps', False)
  1049. ]
  1050. helpers.convert_mapping_to_xml(
  1051. cucumber_result, data, mappings, fail_required=True)
  1052. def xunit(registry, xml_parent, data):
  1053. """yaml: xunit
  1054. Publish tests results. Requires the Jenkins :jenkins-wiki:`xUnit Plugin
  1055. <xUnit+Plugin>`.
  1056. :arg str thresholdmode: Whether thresholds represents an absolute number
  1057. of tests or a percentage. Either 'number' or 'percent'. (default
  1058. 'number')
  1059. :arg list thresholds: Thresholds for both 'failed' and 'skipped' tests.
  1060. :threshold (`dict`): Threshold values to set, where missing, xUnit
  1061. should default to an internal value of 0. Each test threshold
  1062. should contain the following:
  1063. * **unstable** (`int`)
  1064. * **unstablenew** (`int`)
  1065. * **failure** (`int`)
  1066. * **failurenew** (`int`)
  1067. :arg int test-time-margin: Give the report time margin value in ms, before
  1068. to fail if not new unless the option **requireupdate** is set for the
  1069. configured framework. (default 3000)
  1070. :arg list types: Frameworks to configure, and options. Supports the
  1071. following: ``aunit``, ``boosttest``, ``checktype``, ``cpptest``,
  1072. ``cppunit``, ``ctest``, ``dotnettest``, ``embunit``, ``fpcunit``,
  1073. ``gtest``, ``junit``, ``mstest``, ``nunit``, ``phpunit``, ``tusar``,
  1074. ``unittest``, and ``valgrind``.
  1075. The 'custom' type is not supported.
  1076. :type (`dict`): each type can be configured using the following:
  1077. * **pattern** (`str`): An Ant pattern to look for Junit result
  1078. files, relative to the workspace root (default '')
  1079. * **requireupdate** (`bool`): fail the build whenever fresh tests
  1080. results have not been found (default true).
  1081. * **deleteoutput** (`bool`): delete temporary JUnit files
  1082. (default true).
  1083. * **skip-if-no-test-files** (`bool`): Skip parsing this xUnit type
  1084. report if there are no test reports files (default false).
  1085. * **stoponerror** (`bool`): Fail the build whenever an error occur
  1086. during a result file processing (default true).
  1087. Example:
  1088. .. literalinclude:: /../../tests/publishers/fixtures/xunit001.yaml
  1089. :language: yaml
  1090. """
  1091. logger = logging.getLogger(__name__)
  1092. xunit = XML.SubElement(xml_parent, 'xunit')
  1093. xunit.set('plugin', 'xunit')
  1094. # Map our internal types to the XML element names used by Jenkins plugin
  1095. types_to_plugin_types = {
  1096. 'aunit': 'AUnitJunitHudsonTestType',
  1097. 'boosttest': 'BoostTestJunitHudsonTestType',
  1098. 'checktype': 'CheckType',
  1099. 'cpptest': 'CppTestJunitHudsonTestType',
  1100. 'cppunit': 'CppUnitJunitHudsonTestType',
  1101. 'ctest': 'CTestType',
  1102. 'dotnettest': 'XUnitDotNetTestType', # since plugin v1.93
  1103. 'embunit': 'EmbUnitType', # since plugin v1.84
  1104. 'fpcunit': 'FPCUnitJunitHudsonTestType',
  1105. 'gtest': 'GoogleTestType',
  1106. 'junit': 'JUnitType',
  1107. 'mstest': 'MSTestJunitHudsonTestType',
  1108. 'nunit': 'NUnitJunitHudsonTestType',
  1109. 'phpunit': 'PHPUnitJunitHudsonTestType',
  1110. 'tusar': 'TUSARJunitHudsonTestType',
  1111. 'unittest': 'UnitTestJunitHudsonTestType',
  1112. 'valgrind': 'ValgrindJunitHudsonTestType',
  1113. # FIXME should implement the 'custom' type
  1114. }
  1115. implemented_types = types_to_plugin_types.keys() # shortcut
  1116. # Unit framework we are going to generate xml for
  1117. supported_types = []
  1118. for configured_type in data['types']:
  1119. type_name = next(iter(configured_type.keys()))
  1120. if type_name not in implemented_types:
  1121. logger.warning("Requested xUnit type '%s' is not yet supported",
  1122. type_name)
  1123. else:
  1124. # Append for generation
  1125. supported_types.append(configured_type)
  1126. # Generate XML for each of the supported framework types
  1127. xmltypes = XML.SubElement(xunit, 'types')
  1128. for supported_type in supported_types:
  1129. framework_name = next(iter(supported_type.keys()))
  1130. xmlframework = XML.SubElement(xmltypes,
  1131. types_to_plugin_types[framework_name])
  1132. mappings = [
  1133. ('pattern', 'pattern', ''),
  1134. ('requireupdate', 'failIfNotNew', True),
  1135. ('deleteoutput', 'deleteOutputFiles', True),
  1136. ('skip-if-no-test-files', 'skipNoTestFiles', False),
  1137. ('stoponerror', 'stopProcessingIfError', True),
  1138. ]
  1139. helpers.convert_mapping_to_xml(xmlframework,
  1140. supported_type[framework_name],
  1141. mappings,
  1142. fail_required=True)
  1143. xmlthresholds = XML.SubElement(xunit, 'thresholds')
  1144. for t in data.get('thresholds', []):
  1145. if not ('failed' in t or 'skipped' in t):
  1146. logger.warning(
  1147. "Unrecognized threshold, should be 'failed' or 'skipped'")
  1148. continue
  1149. elname = ("org.jenkinsci.plugins.xunit.threshold.%sThreshold" %
  1150. next(iter(t.keys())).title())
  1151. el = XML.SubElement(xmlthresholds, elname)
  1152. for threshold_name, threshold_value in next(iter(t.values())).items():
  1153. # Normalize and craft the element name for this threshold
  1154. elname = "%sThreshold" % threshold_name.lower().replace(
  1155. 'new', 'New')
  1156. XML.SubElement(el, elname).text = str(threshold_value)
  1157. # Whether to use percent of exact number of tests.
  1158. # Thresholdmode is either:
  1159. # - 1 : absolute (number of tests), default.
  1160. # - 2 : relative (percentage of tests)
  1161. thresholdmode = '1'
  1162. if 'percent' == data.get('thresholdmode', 'number'):
  1163. thresholdmode = '2'
  1164. XML.SubElement(xunit, 'thresholdMode').text = thresholdmode
  1165. extra_config = XML.SubElement(xunit, 'extraConfiguration')
  1166. XML.SubElement(extra_config, 'testTimeMargin').text = str(
  1167. data.get('test-time-margin', '3000'))
  1168. def _violations_add_entry(xml_parent, name, data):
  1169. vmin = data.get('min', 10)
  1170. vmax = data.get('max', 999)
  1171. vunstable = data.get('unstable', 999)
  1172. pattern = data.get('pattern', None)
  1173. entry = XML.SubElement(xml_parent, 'entry')
  1174. mapping = [('', 'string', name)]
  1175. helpers.convert_mapping_to_xml(entry, data, mapping, fail_required=True)
  1176. tconfig = XML.SubElement(entry, 'hudson.plugins.violations.TypeConfig')
  1177. mapping = [
  1178. ('', 'type', name),
  1179. ('', 'min', str(vmin)),
  1180. ('', 'max', str(vmax)),
  1181. ('', 'unstable', str(vunstable)),
  1182. ('', 'usePattern', 'false'),
  1183. ]
  1184. helpers.convert_mapping_to_xml(tconfig, data, mapping, fail_required=True)
  1185. if pattern:
  1186. XML.SubElement(tconfig, 'pattern').text = pattern
  1187. else:
  1188. XML.SubElement(tconfig, 'pattern')
  1189. def violations(registry, xml_parent, data):
  1190. """yaml: violations
  1191. Publish code style violations.
  1192. Requires the Jenkins :jenkins-wiki:`Violations Plugin <Violations>`.
  1193. The violations component accepts any number of dictionaries keyed
  1194. by the name of the violations system. The dictionary has the
  1195. following values:
  1196. :arg int min: sunny threshold
  1197. :arg int max: stormy threshold
  1198. :arg int unstable: unstable threshold
  1199. :arg str pattern: report filename pattern
  1200. Any system without a dictionary provided will use default values.
  1201. Valid systems are:
  1202. checkstyle, codenarc, cpd, cpplint, csslint, findbugs, fxcop,
  1203. gendarme, jcreport, jslint, pep8, perlcritic, pmd, pylint,
  1204. simian, stylecop
  1205. Example:
  1206. .. literalinclude:: /../../tests/publishers/fixtures/violations001.yaml
  1207. :language: yaml
  1208. """
  1209. violations = XML.SubElement(xml_parent,
  1210. 'hudson.plugins.violations.'
  1211. 'ViolationsPublisher')
  1212. config = XML.SubElement(violations, 'config')
  1213. suppressions = XML.SubElement(config, 'suppressions',
  1214. {'class': 'tree-set'})
  1215. XML.SubElement(suppressions, 'no-comparator')
  1216. configs = XML.SubElement(config, 'typeConfigs')
  1217. XML.SubElement(configs, 'no-comparator')
  1218. for name in ['checkstyle',
  1219. 'codenarc',
  1220. 'cpd',
  1221. 'cpplint',
  1222. 'csslint',
  1223. 'findbugs',
  1224. 'fxcop',
  1225. 'gendarme',
  1226. 'jcreport',
  1227. 'jslint',
  1228. 'pep8',
  1229. 'perlcritic',
  1230. 'pmd',
  1231. 'pylint',
  1232. 'simian',
  1233. 'stylecop']:
  1234. _violations_add_entry(configs, name, data.get(name, {}))
  1235. mapping = [
  1236. ('', 'limit', '100'),
  1237. ('', 'sourcePathPattern', ''),
  1238. ('', 'fauxProjectPath', ''),
  1239. ('', 'encoding', 'default'),
  1240. ]
  1241. helpers.convert_mapping_to_xml(config, data, mapping, fail_required=True)
  1242. def findbugs(registry, xml_parent, data):
  1243. """yaml: findbugs
  1244. FindBugs reporting for builds
  1245. Requires the Jenkins :jenkins-wiki:`FindBugs Plugin
  1246. <FindBugs+Plugin>`.
  1247. :arg str pattern: specifies the generated raw FindBugs XML report files,
  1248. such as \*\*/findbugs.xml or \*\*/findbugsXml.xml. (default '')
  1249. :arg bool rank-priority: Use rank as priority (default false)
  1250. :arg str include-files: Comma separated list of files to include.
  1251. (default '')
  1252. :arg str exclude-files: Comma separated list of files to exclude.
  1253. (default '')
  1254. :arg bool can-run-on-failed: Weather or not to run plug-in on failed builds
  1255. (default false)
  1256. :arg bool should-detect-modules: Determines if Ant or Maven modules should
  1257. be detected for all files that contain warnings. (default false)
  1258. :arg int healthy: Sunny threshold (default '')
  1259. :arg int unhealthy: Stormy threshold (default '')
  1260. :arg str health-threshold: Threshold priority for health status
  1261. ('low', 'normal' or 'high', defaulted to 'low')
  1262. :arg bool dont-compute-new: If set to false, computes new warnings based on
  1263. the reference build (default true)
  1264. :arg bool use-delta-values: Use delta for new warnings. (default false)
  1265. :arg bool use-previous-build-as-reference: If set then the number of new
  1266. warnings will always be calculated based on the previous build.
  1267. Otherwise the reference build. (default false)
  1268. :arg bool use-stable-build-as-reference: The number of new warnings will be
  1269. calculated based on the last stable build, allowing reverts of unstable
  1270. builds where the number of warnings was decreased. (default false)
  1271. :arg dict thresholds:
  1272. :thresholds:
  1273. * **unstable** (`dict`)
  1274. :unstable: * **total-all** (`int`)
  1275. * **total-high** (`int`)
  1276. * **total-normal** (`int`)
  1277. * **total-low** (`int`)
  1278. * **new-all** (`int`)
  1279. * **new-high** (`int`)
  1280. * **new-normal** (`int`)
  1281. * **new-low** (`int`)
  1282. * **failed** (`dict`)
  1283. :failed: * **total-all** (`int`)
  1284. * **total-high** (`int`)
  1285. * **total-normal** (`int`)
  1286. * **total-low** (`int`)
  1287. * **new-all** (`int`)
  1288. * **new-high** (`int`)
  1289. * **new-normal** (`int`)
  1290. * **new-low** (`int`)
  1291. Minimal Example:
  1292. .. literalinclude:: /../../tests/publishers/fixtures/findbugs-minimal.yaml
  1293. Full Example:
  1294. .. literalinclude:: /../../tests/publishers/fixtures/findbugs-full.yaml
  1295. """
  1296. findbugs = XML.SubElement(xml_parent,
  1297. 'hudson.plugins.findbugs.FindBugsPublisher')
  1298. findbugs.set('plugin', 'findbugs')
  1299. helpers.findbugs_settings(findbugs, data)
  1300. helpers.build_trends_publisher('[FINDBUGS] ', findbugs, data)
  1301. def checkstyle(registry, xml_parent, data):
  1302. """yaml: checkstyle
  1303. Publish trend reports with Checkstyle.
  1304. Requires the Jenkins :jenkins-wiki:`Checkstyle Plugin <Checkstyle+Plugin>`.
  1305. The checkstyle component accepts a dictionary with the
  1306. following values:
  1307. :arg str pattern: Report filename pattern (default '')
  1308. :arg bool can-run-on-failed: Also runs for failed builds, instead of just
  1309. stable or unstable builds (default false)
  1310. :arg bool should-detect-modules: Determines if Ant or Maven modules should
  1311. be detected for all files that contain warnings (default false)
  1312. :arg int healthy: Sunny threshold (default '')
  1313. :arg int unhealthy: Stormy threshold (default '')
  1314. :arg str health-threshold: Threshold priority for health status
  1315. ('low', 'normal' or 'high') (default 'low')
  1316. :arg dict thresholds: Mark build as failed or unstable if the number of
  1317. errors exceeds a threshold. (optional)
  1318. :thresholds:
  1319. * **unstable** (`dict`)
  1320. :unstable: * **total-all** (`int`)
  1321. * **total-high** (`int`)
  1322. * **total-normal** (`int`)
  1323. * **total-low** (`int`)
  1324. * **new-all** (`int`)
  1325. * **new-high** (`int`)
  1326. * **new-normal** (`int`)
  1327. * **new-low** (`int`)
  1328. * **failed** (`dict`)
  1329. :failed: * **total-all** (`int`)
  1330. * **total-high** (`int`)
  1331. * **total-normal** (`int`)
  1332. * **total-low** (`int`)
  1333. * **new-all** (`int`)
  1334. * **new-high** (`int`)
  1335. * **new-normal** (`int`)
  1336. * **new-low** (`int`)
  1337. :arg str default-encoding: Encoding for parsing or showing files
  1338. (default '')
  1339. :arg bool do-not-resolve-relative-paths: (default false)
  1340. :arg bool dont-compute-new: If set to false, computes new warnings based on
  1341. the reference build (default true)
  1342. :arg bool use-previous-build-as-reference: determines whether to always
  1343. use the previous build as the reference build (default false)
  1344. :arg bool use-stable-build-as-reference: The number of new warnings will be
  1345. calculated based on the last stable build, allowing reverts of unstable
  1346. builds where the number of warnings was decreased. (default false)
  1347. :arg bool use-delta-values: If set then the number of new warnings is
  1348. calculated by subtracting the total number of warnings of the current
  1349. build from the reference build. (default false)
  1350. Example:
  1351. .. literalinclude:: /../../tests/publishers/fixtures/checkstyle004.yaml
  1352. :language: yaml
  1353. Full example:
  1354. .. literalinclude:: /../../tests/publishers/fixtures/checkstyle006.yaml
  1355. :language: yaml
  1356. """
  1357. def convert_settings(lookup, data):
  1358. """Helper to convert settings from one key to another
  1359. """
  1360. for old_key in list(data.keys()):
  1361. if old_key in lookup:
  1362. data.setdefault(lookup[old_key], data[old_key])
  1363. del data[old_key]
  1364. checkstyle = XML.SubElement(xml_parent,
  1365. 'hudson.plugins.checkstyle.'
  1366. 'CheckStylePublisher')
  1367. checkstyle.set('plugin', 'checkstyle')
  1368. # Convert old style yaml to new style
  1369. convert_settings({
  1370. 'unHealthy': 'unhealthy',
  1371. 'healthThreshold': 'health-threshold',
  1372. 'defaultEncoding': 'default-encoding',
  1373. 'canRunOnFailed': 'can-run-on-failed',
  1374. 'shouldDetectModules': 'should-detect-modules'
  1375. }, data)
  1376. threshold_data = data.get('thresholds', {})
  1377. for threshold in ['unstable', 'failed']:
  1378. convert_settings({
  1379. 'totalAll': 'total-all',
  1380. 'totalHigh': 'total-high',
  1381. 'totalNormal': 'total-normal',
  1382. 'totalLow': 'total-low'
  1383. }, threshold_data.get(threshold, {}))
  1384. helpers.build_trends_publisher('[CHECKSTYLE] ', checkstyle, data)
  1385. def scp(registry, xml_parent, data):
  1386. """yaml: scp
  1387. Upload files via SCP
  1388. Requires the Jenkins :jenkins-wiki:`SCP Plugin <SCP+plugin>`.
  1389. When writing a publisher macro, it is important to keep in mind that
  1390. Jenkins uses Ant's `SCP Task
  1391. <https://ant.apache.org/manual/Tasks/scp.html>`_ via the Jenkins
  1392. :jenkins-wiki:`SCP Plugin <SCP+plugin>` which relies on `FileSet
  1393. <https://ant.apache.org/manual/Types/fileset.html>`_
  1394. and `DirSet <https://ant.apache.org/manual/Types/dirset.html>`_ patterns.
  1395. The relevant piece of documentation is excerpted below:
  1396. Source points to files which will be uploaded. You can use ant
  1397. includes syntax, eg. ``folder/dist/*.jar``. Path is constructed from
  1398. workspace root. Note that you cannot point files outside the workspace
  1399. directory. For example providing: ``../myfile.txt`` won't work...
  1400. Destination points to destination folder on remote site. It will be
  1401. created if doesn't exists and relative to root repository path. You
  1402. can define multiple blocks of source/destination pairs.
  1403. This means that absolute paths, e.g., ``/var/log/**`` will not work and
  1404. will fail to compile. All paths need to be relative to the directory that
  1405. the publisher runs and the paths have to be contained inside of that
  1406. directory. The relative working directory is usually::
  1407. /home/jenkins/workspace/${JOB_NAME}
  1408. :arg str site: name of the scp site (required)
  1409. :arg str target: destination directory (required)
  1410. :arg str source: source path specifier (default '')
  1411. :arg bool keep-hierarchy: keep the file hierarchy when uploading
  1412. (default false)
  1413. :arg bool copy-after-failure: copy files even if the job fails
  1414. (default false)
  1415. :arg bool copy-console: copy the console log (default false); if
  1416. specified, omit 'source'
  1417. Example:
  1418. .. literalinclude:: /../../tests/publishers/fixtures/scp001.yaml
  1419. :language: yaml
  1420. """
  1421. scp = XML.SubElement(xml_parent,
  1422. 'be.certipost.hudson.plugin.SCPRepositoryPublisher')
  1423. scp.set('plugin', 'scp')
  1424. mappings = [
  1425. ('site', 'siteName', None),
  1426. ]
  1427. helpers.convert_mapping_to_xml(scp, data, mappings, fail_required=True)
  1428. entries = XML.SubElement(scp, 'entries')
  1429. for entry in data['files']:
  1430. entry_e = XML.SubElement(entries, 'be.certipost.hudson.plugin.Entry')
  1431. mappings = [
  1432. ('target', 'filePath', None),
  1433. ('source', 'sourceFile', ''),
  1434. ('keep-hierarchy', 'keepHierarchy', False),
  1435. ('copy-console', 'copyConsoleLog', False),
  1436. ('copy-after-failure', 'copyAfterFailure', False),
  1437. ]
  1438. helpers.convert_mapping_to_xml(
  1439. entry_e, entry, mappings, fail_required=True)
  1440. def ssh(registry, xml_parent, data):
  1441. """yaml: ssh
  1442. Upload files via SCP.
  1443. Requires the Jenkins :jenkins-wiki:`Publish over SSH Plugin
  1444. <Publish+Over+SSH+Plugin>`.
  1445. :arg str site: name of the ssh site
  1446. :arg str target: destination directory
  1447. :arg bool target-is-date-format: whether target is a date format. If true,
  1448. raw text should be quoted (default false)
  1449. :arg bool clean-remote: should the remote directory be deleted before
  1450. transferring files (default false)
  1451. :arg str source: source path specifier
  1452. :arg str command: a command to execute on the remote server (optional)
  1453. :arg int timeout: timeout in milliseconds for the Exec command (optional)
  1454. :arg bool use-pty: run the exec command in pseudo TTY (default false)
  1455. :arg str excludes: excluded file pattern (optional)
  1456. :arg str remove-prefix: prefix to remove from uploaded file paths
  1457. (optional)
  1458. :arg bool fail-on-error: fail the build if an error occurs (default false).
  1459. :arg bool always-publish-from-master: transfer the files through the master
  1460. before being sent to the remote server (defaults false)
  1461. :arg bool flatten: only create files on the server, don't create
  1462. directories (default false).
  1463. Example:
  1464. .. literalinclude:: /../../tests/publishers/fixtures/ssh001.yaml
  1465. :language: yaml
  1466. """
  1467. console_prefix = 'SSH: '
  1468. tag_prefix = 'jenkins.plugins.publish'
  1469. publisher_tag = '%s__over__ssh.BapSshPublisher' % tag_prefix
  1470. transfer_tag = '%s__over__ssh.BapSshTransfer' % tag_prefix
  1471. reference_tag = '%s_over_ssh.BapSshPublisherPlugin' % tag_prefix
  1472. if xml_parent.tag == 'publishers':
  1473. plugin_tag = '%s__over__ssh.BapSshPublisherPlugin' % tag_prefix
  1474. else:
  1475. plugin_tag = '%s__over__ssh.BapSshBuilderPlugin' % tag_prefix
  1476. base_publish_over(xml_parent, data, console_prefix, plugin_tag,
  1477. publisher_tag, transfer_tag, reference_tag)
  1478. def pipeline(registry, xml_parent, data):
  1479. """yaml: pipeline
  1480. Specify a downstream project in a pipeline.
  1481. Requires the Jenkins :jenkins-wiki:`Build Pipeline Plugin
  1482. <Build+Pipeline+Plugin>`.
  1483. Use of the `node-label-name` or `node-label` parameters
  1484. requires the Jenkins :jenkins-wiki:`NodeLabel Parameter Plugin
  1485. <NodeLabel+Parameter+Plugin>`.
  1486. Note: 'node-parameters' overrides the Node that the triggered
  1487. project is tied to.
  1488. :arg list projects: list the jobs to trigger, will generate comma-separated
  1489. string containing the named jobs.
  1490. :arg str predefined-parameters: parameters to pass to the other
  1491. job (optional)
  1492. :arg bool current-parameters: Whether to include the parameters passed
  1493. to the current build to the triggered job (optional)
  1494. :arg bool node-parameters: Use the same Node for the triggered builds
  1495. that was used for this build. (optional)
  1496. :arg bool svn-revision: Pass svn revision to the triggered job (optional)
  1497. :arg bool include-upstream: Include/pass through Upstream SVN Revisons.
  1498. Only valid when 'svn-revision' is true. (default false)
  1499. :arg dict git-revision: Passes git revision to the triggered job
  1500. (optional).
  1501. * **combine-queued-commits** (bool): Whether to combine queued git
  1502. hashes or not (default false)
  1503. :arg dict boolean-parameters: Pass boolean parameters to the downstream
  1504. jobs. Specify the name and boolean value mapping of the parameters.
  1505. (optional)
  1506. :arg str property-file: Use properties from file (optional)
  1507. :arg bool fail-on-missing: Blocks the triggering of the downstream jobs
  1508. if any of the property files are not found in the workspace.
  1509. Only valid when 'property-file' is specified.
  1510. (default false)
  1511. :arg str file-encoding: Encoding of contents of the files. If not
  1512. specified, default encoding of the platform is used. Only valid when
  1513. 'property-file' is specified. (optional)
  1514. :arg str restrict-matrix-project: Filter that restricts the subset
  1515. of the combinations that the downstream project will run (optional)
  1516. Example:
  1517. .. literalinclude:: /../../tests/publishers/fixtures/pipeline002.yaml
  1518. :language: yaml
  1519. .. literalinclude:: /../../tests/publishers/fixtures/pipeline003.yaml
  1520. :language: yaml
  1521. You can build pipeline jobs that are re-usable in different pipelines by
  1522. using a :ref:`job-template` to define the pipeline jobs,
  1523. and variable substitution to specify the name of
  1524. the downstream job in the pipeline.
  1525. Job-specific substitutions are useful here (see :ref:`project`).
  1526. See 'samples/pipeline.yaml' for an example pipeline implementation.
  1527. """
  1528. logger = logging.getLogger("%s:pipeline" % __name__)
  1529. param_order = helpers.trigger_get_parameter_order(registry, 'pipeline')
  1530. if 'project' in data:
  1531. logger.warning(
  1532. "Using 'project' for pipeline definition is deprecated. Please "
  1533. "update your job definition to use 'projects' with a list format.")
  1534. projects = ",".join(data.get('projects', [data.get('project', '')]))
  1535. if projects != '':
  1536. pippub = XML.SubElement(xml_parent,
  1537. 'au.com.centrumsystems.hudson.plugin.'
  1538. 'buildpipeline.trigger.BuildPipelineTrigger')
  1539. configs = XML.SubElement(pippub, 'configs')
  1540. helpers.trigger_project(configs, data, param_order)
  1541. XML.SubElement(pippub, 'downstreamProjectNames').text = projects
  1542. def email(registry, xml_parent, data):
  1543. """yaml: email
  1544. Email notifications on build failure.
  1545. Requires the Jenkins :jenkins-wiki:`Mailer Plugin
  1546. <Mailer>`.
  1547. :arg str recipients: Space separated list of recipient email addresses
  1548. (required)
  1549. :arg bool notify-every-unstable-build: Send an email for every
  1550. unstable build (default true)
  1551. :arg bool send-to-individuals: Send an email to the individual
  1552. who broke the build (default false)
  1553. Example:
  1554. .. literalinclude::
  1555. /../../tests/publishers/fixtures/email-minimal.yaml
  1556. :language: yaml
  1557. .. literalinclude:: /../../tests/publishers/fixtures/email-full.yaml
  1558. :language: yaml
  1559. """
  1560. # TODO: raise exception if this is applied to a maven job
  1561. mailer = XML.SubElement(xml_parent,
  1562. 'hudson.tasks.Mailer')
  1563. mailer.set('plugin', 'mailer')
  1564. mapping = [
  1565. ('recipients', 'recipients', None)
  1566. ]
  1567. helpers.convert_mapping_to_xml(mailer, data, mapping, fail_required=True)
  1568. # Note the logic reversal (included here to match the GUI
  1569. if data.get('notify-every-unstable-build', True):
  1570. XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
  1571. else:
  1572. XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
  1573. XML.SubElement(mailer, 'sendToIndividuals').text = str(
  1574. data.get('send-to-individuals', False)).lower()
  1575. def claim_build(registry, xml_parent, data):
  1576. """yaml: claim-build
  1577. Claim build failures
  1578. Requires the Jenkins :jenkins-wiki:`Claim Plugin <Claim+plugin>`.
  1579. Example:
  1580. .. literalinclude:: /../../tests/publishers/fixtures/claim-build001.yaml
  1581. :language: yaml
  1582. """
  1583. XML.SubElement(xml_parent, 'hudson.plugins.claim.ClaimPublisher')
  1584. def base_email_ext(registry, xml_parent, data, ttype):
  1585. trigger = XML.SubElement(xml_parent,
  1586. 'hudson.plugins.emailext.plugins.trigger.'
  1587. + ttype)
  1588. email = XML.SubElement(trigger, 'email')
  1589. XML.SubElement(email, 'recipientList').text = ''
  1590. XML.SubElement(email, 'subject').text = '$PROJECT_DEFAULT_SUBJECT'
  1591. XML.SubElement(email, 'body').text = '$PROJECT_DEFAULT_CONTENT'
  1592. if 'send-to' in data:
  1593. XML.SubElement(email, 'sendToDevelopers').text = str(
  1594. 'developers' in data['send-to']).lower()
  1595. XML.SubElement(email, 'sendToRequester').text = str(
  1596. 'requester' in data['send-to']).lower()
  1597. XML.SubElement(email, 'includeCulprits').text = str(
  1598. 'culprits' in data['send-to']).lower()
  1599. XML.SubElement(email, 'sendToRecipientList').text = str(
  1600. 'recipients' in data['send-to']).lower()
  1601. else:
  1602. XML.SubElement(email, 'sendToRequester').text = 'false'
  1603. XML.SubElement(email, 'sendToDevelopers').text = 'false'
  1604. XML.SubElement(email, 'includeCulprits').text = 'false'
  1605. XML.SubElement(email, 'sendToRecipientList').text = 'true'
  1606. if ttype == 'ScriptTrigger':
  1607. XML.SubElement(trigger, 'triggerScript').text = data['trigger-script']
  1608. def email_ext(registry, xml_parent, data):
  1609. """yaml: email-ext
  1610. Extend Jenkin's built in email notification
  1611. Requires the Jenkins :jenkins-wiki:`Email-ext Plugin
  1612. <Email-ext+plugin>`.
  1613. :arg bool disable-publisher: Disable the publisher, while maintaining the
  1614. settings. The usage model for this is when you want to test things out
  1615. in the build, not send out e-mails during the testing. A message will
  1616. be printed to the build log saying that the publisher is disabled.
  1617. (default false)
  1618. :arg str recipients: Comma separated list of recipient email addresses
  1619. (default '$DEFAULT_RECIPIENTS')
  1620. :arg str reply-to: Comma separated list of email addresses that should be
  1621. in the Reply-To header for this project (default '$DEFAULT_REPLYTO')
  1622. :arg str content-type: The content type of the emails sent. If not set, the
  1623. Jenkins plugin uses the value set on the main configuration page.
  1624. Possible values: 'html', 'text', 'both-html-text' or 'default'
  1625. (default 'default')
  1626. :arg str subject: Subject for the email, can include variables like
  1627. ${BUILD_NUMBER} or even groovy or javascript code
  1628. (default '$DEFAULT_SUBJECT')
  1629. :arg str body: Content for the body of the email, can include variables
  1630. like ${BUILD_NUMBER}, but the real magic is using groovy or
  1631. javascript to hook into the Jenkins API itself
  1632. (default '$DEFAULT_CONTENT')
  1633. :arg bool attach-build-log: Include build log in the email (default false)
  1634. :arg bool compress-log: Compress build log in the email (default false)
  1635. :arg str attachments: pattern of files to include as attachment
  1636. (default '')
  1637. :arg bool always: Send an email for every result (default false)
  1638. :arg bool unstable: Send an email for an unstable result (default false)
  1639. :arg bool first-failure: Send an email for just the first failure
  1640. (default false)
  1641. :arg bool first-unstable: Send an email for just the first unstable build
  1642. (default false)
  1643. :arg bool not-built: Send an email if not built (default false)
  1644. :arg bool aborted: Send an email if the build is aborted (default false)
  1645. :arg bool regression: Send an email if there is a regression
  1646. (default false)
  1647. :arg bool failure: Send an email if the build fails (default true)
  1648. :arg bool second-failure: Send an email for the second failure
  1649. (default false)
  1650. :arg bool improvement: Send an email if the build improves (default false)
  1651. :arg bool still-failing: Send an email if the build is still failing
  1652. (default false)
  1653. :arg bool success: Send an email for a successful build (default false)
  1654. :arg bool fixed: Send an email if the build is fixed (default false)
  1655. :arg bool fixed-unhealthy: Send an email if the build status
  1656. changes from "Failure" or "Unstable" to "Success". Intermediate
  1657. "Aborted" builds are ignored. (default false)
  1658. :arg bool still-unstable: Send an email if the build is still unstable
  1659. (default false)
  1660. :arg bool pre-build: Send an email before the build (default false)
  1661. :arg str trigger-script: A Groovy script used to determine if an email
  1662. should be sent.
  1663. :arg str presend-script: A Groovy script executed prior sending the mail.
  1664. (default '')
  1665. :arg str postsend-script: A Goovy script executed after sending the email.
  1666. (default '')
  1667. :arg bool save-output: Save email content to workspace (default false)
  1668. :arg str matrix-trigger: If using matrix projects, when to trigger
  1669. :matrix-trigger values:
  1670. * **both**
  1671. * **only-parent**
  1672. * **only-configurations**
  1673. :arg list send-to: list of recipients from the predefined groups
  1674. :send-to values:
  1675. * **developers** (disabled by default)
  1676. * **requester** (disabled by default)
  1677. * **culprits** (disabled by default)
  1678. * **recipients** (enabled by default)
  1679. Example:
  1680. .. literalinclude:: /../../tests/publishers/fixtures/email-ext001.yaml
  1681. :language: yaml
  1682. """
  1683. emailext = XML.SubElement(xml_parent,
  1684. 'hudson.plugins.emailext.ExtendedEmailPublisher')
  1685. if 'recipients' in data:
  1686. XML.SubElement(emailext, 'recipientList').text = data['recipients']
  1687. else:
  1688. XML.SubElement(emailext, 'recipientList').text = '$DEFAULT_RECIPIENTS'
  1689. ctrigger = XML.SubElement(emailext, 'configuredTriggers')
  1690. if data.get('always', False):
  1691. base_email_ext(registry, ctrigger, data, 'AlwaysTrigger')
  1692. if data.get('unstable', False):
  1693. base_email_ext(registry, ctrigger, data, 'UnstableTrigger')
  1694. if data.get('first-failure', False):
  1695. base_email_ext(registry, ctrigger, data, 'FirstFailureTrigger')
  1696. if data.get('first-unstable', False):
  1697. base_email_ext(registry, ctrigger, data, 'FirstUnstableTrigger')
  1698. if data.get('not-built', False):
  1699. base_email_ext(registry, ctrigger, data, 'NotBuiltTrigger')
  1700. if data.get('aborted', False):
  1701. base_email_ext(registry, ctrigger, data, 'AbortedTrigger')
  1702. if data.get('regression', False):
  1703. base_email_ext(registry, ctrigger, data, 'RegressionTrigger')
  1704. if data.get('failure', True):
  1705. base_email_ext(registry, ctrigger, data, 'FailureTrigger')
  1706. if data.get('second-failure', False):
  1707. base_email_ext(registry, ctrigger, data, 'SecondFailureTrigger')
  1708. if data.get('improvement', False):
  1709. base_email_ext(registry, ctrigger, data, 'ImprovementTrigger')
  1710. if data.get('still-failing', False):
  1711. base_email_ext(registry, ctrigger, data, 'StillFailingTrigger')
  1712. if data.get('success', False):
  1713. base_email_ext(registry, ctrigger, data, 'SuccessTrigger')
  1714. if data.get('fixed', False):
  1715. base_email_ext(registry, ctrigger, data, 'FixedTrigger')
  1716. if data.get('fixed-unhealthy', False):
  1717. base_email_ext(registry, ctrigger, data, 'FixedUnhealthyTrigger')
  1718. if data.get('still-unstable', False):
  1719. base_email_ext(registry, ctrigger, data, 'StillUnstableTrigger')
  1720. if data.get('pre-build', False):
  1721. base_email_ext(registry, ctrigger, data, 'PreBuildTrigger')
  1722. if data.get('trigger-script', False):
  1723. base_email_ext(registry, ctrigger, data, 'ScriptTrigger')
  1724. content_type_mime = {
  1725. 'text': 'text/plain',
  1726. 'html': 'text/html',
  1727. 'default': 'default',
  1728. 'both-html-text': 'both',
  1729. }
  1730. ctype = data.get('content-type', 'default')
  1731. if ctype not in content_type_mime:
  1732. raise JenkinsJobsException('email-ext content type must be one of: %s'
  1733. % ', '.join(content_type_mime.keys()))
  1734. XML.SubElement(emailext, 'contentType').text = content_type_mime[ctype]
  1735. mappings = [
  1736. ('subject', 'defaultSubject', '$DEFAULT_SUBJECT'),
  1737. ('body', 'defaultContent', '$DEFAULT_CONTENT'),
  1738. ('attachments', 'attachmentsPattern', ''),
  1739. ('presend-script', 'presendScript', ''),
  1740. ('postsend-script', 'postsendScript', ''),
  1741. ('attach-build-log', 'attachBuildLog', False),
  1742. ('compress-log', 'compressBuildLog', False),
  1743. ('save-output', 'saveOutput', False),
  1744. ('disable-publisher', 'disabled', False),
  1745. ('reply-to', 'replyTo', '$DEFAULT_REPLYTO'),
  1746. ]
  1747. helpers.convert_mapping_to_xml(
  1748. emailext, data, mappings, fail_required=True)
  1749. matrix_dict = {'both': 'BOTH',
  1750. 'only-configurations': 'ONLY_CONFIGURATIONS',
  1751. 'only-parent': 'ONLY_PARENT'}
  1752. matrix_trigger = data.get('matrix-trigger', None)
  1753. # If none defined, then do not create entry
  1754. if matrix_trigger is not None:
  1755. if matrix_trigger not in matrix_dict:
  1756. raise JenkinsJobsException("matrix-trigger entered is not valid, "
  1757. "must be one of: %s" %
  1758. ", ".join(matrix_dict.keys()))
  1759. XML.SubElement(emailext, 'matrixTriggerMode').text = matrix_dict.get(
  1760. matrix_trigger)
  1761. def fingerprint(registry, xml_parent, data):
  1762. """yaml: fingerprint
  1763. Fingerprint files to track them across builds. Requires the
  1764. Jenkins :jenkins-wiki:`Fingerprint Plugin <Fingerprint+Plugin>`.
  1765. :arg str files: files to fingerprint, follows the @includes of Ant fileset
  1766. (default '')
  1767. :arg bool record-artifacts: fingerprint all archived artifacts
  1768. (default false)
  1769. Example:
  1770. .. literalinclude:: /../../tests/publishers/fixtures/fingerprint001.yaml
  1771. :language: yaml
  1772. """
  1773. finger = XML.SubElement(xml_parent, 'hudson.tasks.Fingerprinter')
  1774. mappings = [
  1775. ('files', 'targets', ''),
  1776. ('record-artifacts', 'recordBuildArtifacts', False)
  1777. ]
  1778. helpers.convert_mapping_to_xml(finger, data, mappings, fail_required=True)
  1779. def aggregate_tests(registry, xml_parent, data):
  1780. """yaml: aggregate-tests
  1781. Aggregate downstream test results
  1782. :arg bool include-failed-builds: whether to include failed builds
  1783. (default false)
  1784. Example:
  1785. .. literalinclude::
  1786. /../../tests/publishers/fixtures/aggregate-tests001.yaml
  1787. :language: yaml
  1788. """
  1789. agg = XML.SubElement(xml_parent,
  1790. 'hudson.tasks.test.AggregatedTestResultPublisher')
  1791. mapping = [('include-failed-builds', 'includeFailedBuilds', False)]
  1792. helpers.convert_mapping_to_xml(agg, data, mapping, fail_required=True)
  1793. def aggregate_flow_tests(registry, xml_parent, data):
  1794. """yaml: aggregate-flow-tests
  1795. Aggregate downstream test results in a Build Flow job.
  1796. Requires the Jenkins :jenkins-wiki:`Build Flow Test Aggregator Plugin
  1797. <Build+Flow+Test+Aggregator+Plugin>`.
  1798. :arg bool show-test-results-trend: whether to show test results
  1799. trend graph (default true)
  1800. Example:
  1801. .. literalinclude::
  1802. /../../tests/publishers/fixtures/aggregate-flow-tests002.yaml
  1803. :language: yaml
  1804. """
  1805. agg_flow = XML.SubElement(xml_parent, 'org.zeroturnaround.jenkins.'
  1806. 'flowbuildtestaggregator.FlowTestAggregator')
  1807. mapping = [('show-test-results-trend', 'showTestResultTrend', True)]
  1808. helpers.convert_mapping_to_xml(agg_flow, data, mapping, fail_required=True)
  1809. def cppcheck(registry, xml_parent, data):
  1810. """yaml: cppcheck
  1811. Cppcheck result publisher
  1812. Requires the Jenkins :jenkins-wiki:`Cppcheck Plugin <Cppcheck+Plugin>`.
  1813. :arg str pattern: File pattern for cppcheck xml report (required)
  1814. :arg bool ignoreblankfiles: Ignore blank files (default false)
  1815. :arg bool allow-no-report: Do not fail the build if the Cppcheck report
  1816. is not found (default false)
  1817. :arg dict thresholds:
  1818. :thresholds: Configure the build status and health. A build is
  1819. considered as unstable or failure if the new or total number
  1820. of issues exceeds the specified thresholds. The build health
  1821. is also determined by thresholds. If the actual number of issues
  1822. is between the provided thresholds, then the build health is
  1823. interpolated.
  1824. * **unstable** (`str`): Total number unstable threshold (default '')
  1825. * **new-unstable** (`str`): New number unstable threshold (default '')
  1826. * **failure** (`str`): Total number failure threshold (default '')
  1827. * **new-failure** (`str`): New number failure threshold (default '')
  1828. * **healthy** (`str`): Healthy threshold (default '')
  1829. * **unhealthy** (`str`): Unhealthy threshold (default '')
  1830. :arg dict severity:
  1831. :severity: Determines which severity of issues should be considered
  1832. when evaluating the build status and health, default all true
  1833. * **error** (`bool`): Severity error (default true)
  1834. * **warning** (`bool`): Severity warning (default true)
  1835. * **style** (`bool`): Severity style (default true)
  1836. * **performance** (`bool`): Severity performance (default true)
  1837. * **information** (`bool`): Severity information (default true)
  1838. * **nocategory** (`bool`): Severity nocategory (default true)
  1839. * **portability** (`bool`): Severity portability (default true)
  1840. :arg dict graph:
  1841. :graph: Graph configuration
  1842. * **xysize** (`array`): Chart width and height (default [500, 200])
  1843. * **num-builds-in-graph** (`int`): Builds number in graph (default 0)
  1844. :arg dict display
  1845. :display: which errors to display, default only sum
  1846. * **sum** (`bool`): Display sum of all issues (default true)
  1847. * **error** (`bool`): Display errors (default false)
  1848. * **warning** (`bool`): Display warnings (default false)
  1849. * **style** (`bool`): Display style (default false)
  1850. * **performance** (`bool`): Display performance (default false)
  1851. * **information** (`bool`): Display information (default false)
  1852. * **nocategory** (`bool`): Display no category (default false)
  1853. * **portability** (`bool`): Display portability (default false)
  1854. Minimal Example:
  1855. .. literalinclude::
  1856. /../../tests/publishers/fixtures/cppcheck-minimal.yaml
  1857. :language: yaml
  1858. Full Example:
  1859. .. literalinclude::
  1860. /../../tests/publishers/fixtures/cppcheck-full.yaml
  1861. :language: yaml
  1862. """
  1863. cppextbase = XML.SubElement(xml_parent,
  1864. 'org.jenkinsci.plugins.cppcheck.'
  1865. 'CppcheckPublisher')
  1866. cppextbase.set('plugin', 'cppcheck')
  1867. cppext = XML.SubElement(cppextbase, 'cppcheckConfig')
  1868. mappings = [
  1869. ('pattern', 'pattern', None),
  1870. ('ignoreblankfiles', 'ignoreBlankFiles', False),
  1871. ('allow-no-report', 'allowNoReport', False)
  1872. ]
  1873. helpers.convert_mapping_to_xml(cppext, data, mappings, fail_required=True)
  1874. csev = XML.SubElement(cppext, 'configSeverityEvaluation')
  1875. thrsh = data.get('thresholds', {})
  1876. thrsh_mappings = [
  1877. ('unstable', 'threshold', ''),
  1878. ('new-unstable', 'newThreshold', ''),
  1879. ('failure', 'failureThreshold', ''),
  1880. ('new-failure', 'newFailureThreshold', ''),
  1881. ('healthy', 'healthy', ''),
  1882. ('unhealthy', 'unHealthy', '')
  1883. ]
  1884. helpers.convert_mapping_to_xml(
  1885. csev, thrsh, thrsh_mappings, fail_required=True)
  1886. sev = thrsh.get('severity', {})
  1887. sev_mappings = [
  1888. ('error', 'severityError', True),
  1889. ('warning', 'severityWarning', True),
  1890. ('style', 'severityStyle', True),
  1891. ('performance', 'severityPerformance', True),
  1892. ('information', 'severityInformation', True),
  1893. ('nocategory', 'severityNoCategory', True),
  1894. ('portability', 'severityPortability', True)
  1895. ]
  1896. helpers.convert_mapping_to_xml(
  1897. csev, sev, sev_mappings, fail_required=True)
  1898. graph = data.get('graph', {})
  1899. cgraph = XML.SubElement(cppext, 'configGraph')
  1900. x, y = graph.get('xysize', [500, 200])
  1901. XML.SubElement(cgraph, 'xSize').text = str(x)
  1902. XML.SubElement(cgraph, 'ySize').text = str(y)
  1903. graph_mapping = [
  1904. ('num-builds-in-graph', 'numBuildsInGraph', 0)
  1905. ]
  1906. helpers.convert_mapping_to_xml(
  1907. cgraph, graph, graph_mapping, fail_required=True)
  1908. gdisplay = graph.get('display', {})
  1909. gdisplay_mappings = [
  1910. ('sum', 'displayAllErrors', True),
  1911. ('error', 'displayErrorSeverity', False),
  1912. ('warning', 'displayWarningSeverity', False),
  1913. ('style', 'displayStyleSeverity', False),
  1914. ('performance', 'displayPerformanceSeverity', False),
  1915. ('information', 'displayInformationSeverity', False),
  1916. ('nocategory', 'displayNoCategorySeverity', False),
  1917. ('portability', 'displayPortabilitySeverity', False)
  1918. ]
  1919. helpers.convert_mapping_to_xml(
  1920. cgraph, gdisplay, gdisplay_mappings, fail_required=True)
  1921. def logparser(registry, xml_parent, data):
  1922. """yaml: logparser
  1923. Requires the Jenkins :jenkins-wiki:`Log Parser Plugin <Log+Parser+Plugin>`.
  1924. :arg str parse-rules: full path to parse rules (default '')
  1925. :arg bool use-project-rules: use project rules instead of global
  1926. (default true)
  1927. :arg bool unstable-on-warning: mark build unstable on warning
  1928. (default false)
  1929. :arg bool fail-on-error: mark build failed on error (default false)
  1930. :arg bool show-graphs: show parser trend graphs (default true)
  1931. Example:
  1932. Minimal Example:
  1933. .. literalinclude::
  1934. /../../tests/publishers/fixtures/logparser-minimal.yaml
  1935. :language: yaml
  1936. Full Example:
  1937. .. literalinclude::
  1938. /../../tests/publishers/fixtures/logparser-full.yaml
  1939. :language: yaml
  1940. """
  1941. clog = XML.SubElement(xml_parent,
  1942. 'hudson.plugins.logparser.LogParserPublisher')
  1943. clog.set('plugin', 'log-parser')
  1944. rules_path_element = ("projectRulePath"
  1945. if data.get("use-project-rules", True)
  1946. else "parsingRulesPath")
  1947. mappings = [
  1948. ('unstable-on-warning', 'unstableOnWarning', False),
  1949. ('fail-on-error', 'failBuildOnError', False),
  1950. ('show-graphs', 'showGraphs', True),
  1951. ('use-project-rules', 'useProjectRule', True),
  1952. ('parse-rules', rules_path_element, ''),
  1953. ]
  1954. helpers.convert_mapping_to_xml(clog, data, mappings, fail_required=True)
  1955. def copy_to_master(registry, xml_parent, data):
  1956. """yaml: copy-to-master
  1957. Copy files to master from slave
  1958. Requires the Jenkins :jenkins-wiki:`Copy To Slave Plugin
  1959. <Copy+To+Slave+Plugin>`.
  1960. :arg list includes: list of file patterns to copy
  1961. :arg list excludes: list of file patterns to exclude
  1962. :arg string destination: absolute path into which the files will be copied.
  1963. If left blank they will be copied into the workspace of the current job
  1964. (default '')
  1965. :arg bool run-after-result: If this is checked then copying files back to
  1966. master will not run until the build result is finalized.(default true)
  1967. Example:
  1968. .. literalinclude::
  1969. /../../tests/publishers/fixtures/copy-to-master001.yaml
  1970. :language: yaml
  1971. """
  1972. cm = XML.SubElement(xml_parent, 'com.michelin.'
  1973. 'cio.hudson.plugins.copytoslave.CopyToMasterNotifier')
  1974. cm.set('plugin', 'copy-to-slave')
  1975. XML.SubElement(cm, 'includes').text = ','.join(data.get('includes', ['']))
  1976. XML.SubElement(cm, 'excludes').text = ','.join(data.get('excludes', ['']))
  1977. mappings = [
  1978. ('run-after-result', 'runAfterResultFinalised', True),
  1979. ('destination', 'destinationFolder', '')
  1980. ]
  1981. helpers.convert_mapping_to_xml(cm, data, mappings, fail_required=True)
  1982. if data.get('destination', ''):
  1983. XML.SubElement(cm, 'overrideDestinationFolder').text = 'true'
  1984. def jira(registry, xml_parent, data):
  1985. """yaml: jira
  1986. Update relevant JIRA issues
  1987. Requires the Jenkins :jenkins-wiki:`JIRA Plugin <JIRA+Plugin>`.
  1988. Example:
  1989. .. literalinclude:: /../../tests/publishers/fixtures/jira001.yaml
  1990. :language: yaml
  1991. """
  1992. XML.SubElement(xml_parent, 'hudson.plugins.jira.JiraIssueUpdater')
  1993. def growl(registry, xml_parent, data):
  1994. """yaml: growl
  1995. Push notifications to growl client.
  1996. Requires the Jenkins :jenkins-wiki:`Growl Plugin <Growl+Plugin>`.
  1997. :arg str ip: IP address to send growl notifications to (required)
  1998. :arg bool notify-only-on-fail-or-recovery: send a growl only when build
  1999. fails or recovers from a failure (default false)
  2000. Minimal Example:
  2001. .. literalinclude:: /../../tests/publishers/fixtures/growl-minimal.yaml
  2002. :language: yaml
  2003. Full Example:
  2004. .. literalinclude:: /../../tests/publishers/fixtures/growl-full.yaml
  2005. :language: yaml
  2006. """
  2007. growl = XML.SubElement(xml_parent, 'hudson.plugins.growl.GrowlPublisher')
  2008. growl.set('plugin', 'growl')
  2009. mapping = [
  2010. ('ip', 'IP', None),
  2011. ('notify-only-on-fail-or-recovery', 'onlyOnFailureOrRecovery', False),
  2012. ]
  2013. helpers.convert_mapping_to_xml(growl, data, mapping, fail_required=True)
  2014. def groovy_postbuild(registry, xml_parent, data):
  2015. """yaml: groovy-postbuild
  2016. Execute a groovy script.
  2017. Requires the Jenkins :jenkins-wiki:`Groovy Postbuild Plugin
  2018. <Groovy+Postbuild+Plugin>`.
  2019. Please pay attention on version of plugin you have installed.
  2020. There were incompatible changes between 1.x and 2.x. Please see
  2021. :jenkins-wiki:`home page <Groovy+Postbuild+Plugin>` of this plugin
  2022. for full information including migration process.
  2023. :arg str script: The groovy script to execute
  2024. :arg list classpath: List of additional classpaths (>=1.6)
  2025. :arg str on-failure: In case of script failure leave build as it is
  2026. for "nothing" option, mark build as unstable
  2027. for "unstable" and mark job as failure for "failed"
  2028. (default 'nothing')
  2029. :arg bool matrix-parent: Run script for matrix parent only (>=1.9)
  2030. (default false)
  2031. :arg bool sandbox: Execute script inside of groovy sandbox (>=2.0)
  2032. (default false)
  2033. Example:
  2034. .. literalinclude::
  2035. /../../tests/publishers/fixtures/groovy-postbuild001.yaml
  2036. :language: yaml
  2037. """
  2038. logger = logging.getLogger("%s:groovy-postbuild" % __name__)
  2039. # Backward compatibility with old format
  2040. if isinstance(data, six.string_types):
  2041. logger.warning(
  2042. "You use deprecated configuration, please follow documentation "
  2043. "to change configuration. It is not going to be supported in "
  2044. "future releases!"
  2045. )
  2046. data = {
  2047. 'script': data,
  2048. }
  2049. # There are incompatible changes, we need to know version
  2050. info = registry.get_plugin_info('groovy-postbuild')
  2051. # Note: Assume latest version of plugin is preferred config format
  2052. version = pkg_resources.parse_version(
  2053. info.get('version', str(sys.maxsize)))
  2054. # Version specific predicates
  2055. matrix_parent_support = version >= pkg_resources.parse_version("1.9")
  2056. security_plugin_support = version >= pkg_resources.parse_version("2.0")
  2057. extra_classpath_support = version >= pkg_resources.parse_version("1.6")
  2058. root_tag = (
  2059. 'org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder'
  2060. )
  2061. groovy = XML.SubElement(xml_parent, root_tag)
  2062. behavior = data.get('on-failure')
  2063. XML.SubElement(groovy, 'behavior').text = {
  2064. 'unstable': '1',
  2065. 'failed': '2',
  2066. }.get(behavior, '0')
  2067. if matrix_parent_support:
  2068. XML.SubElement(
  2069. groovy,
  2070. 'runForMatrixParent',
  2071. ).text = str(data.get('matrix-parent', False)).lower()
  2072. classpaths = data.get('classpath', list())
  2073. if security_plugin_support:
  2074. script = XML.SubElement(groovy, 'script')
  2075. XML.SubElement(script, 'script').text = data.get('script')
  2076. XML.SubElement(script, 'sandbox').text = str(
  2077. data.get('sandbox', False)
  2078. ).lower()
  2079. if classpaths:
  2080. classpath = XML.SubElement(script, 'classpath')
  2081. for path in classpaths:
  2082. script_path = XML.SubElement(classpath, 'entry')
  2083. XML.SubElement(script_path, 'url').text = path
  2084. else:
  2085. XML.SubElement(groovy, 'groovyScript').text = data.get('script')
  2086. if extra_classpath_support and classpaths:
  2087. classpath = XML.SubElement(groovy, 'classpath')
  2088. for path in classpaths:
  2089. script_path = XML.SubElement(
  2090. classpath,
  2091. 'org.jvnet.hudson.plugins.groovypostbuild.'
  2092. 'GroovyScriptPath',
  2093. )
  2094. XML.SubElement(script_path, 'path').text = path
  2095. def base_publish_over(xml_parent, data, console_prefix,
  2096. plugin_tag, publisher_tag,
  2097. transferset_tag, reference_plugin_tag):
  2098. outer = XML.SubElement(xml_parent, plugin_tag)
  2099. # 'Publish over SSH' builder has an extra top delegate element
  2100. if xml_parent.tag == 'builders':
  2101. outer = XML.SubElement(outer, 'delegate')
  2102. XML.SubElement(outer, 'consolePrefix').text = console_prefix
  2103. delegate = XML.SubElement(outer, 'delegate')
  2104. publishers = XML.SubElement(delegate, 'publishers')
  2105. inner = XML.SubElement(publishers, publisher_tag)
  2106. XML.SubElement(inner, 'configName').text = data['site']
  2107. XML.SubElement(inner, 'verbose').text = 'true'
  2108. transfers = XML.SubElement(inner, 'transfers')
  2109. transfersset = XML.SubElement(transfers, transferset_tag)
  2110. XML.SubElement(transfersset, 'remoteDirectory').text = data['target']
  2111. XML.SubElement(transfersset, 'sourceFiles').text = data['source']
  2112. XML.SubElement(transfersset, 'excludes').text = data.get('excludes', '')
  2113. XML.SubElement(transfersset, 'removePrefix').text = data.get(
  2114. 'remove-prefix', '')
  2115. XML.SubElement(transfersset, 'remoteDirectorySDF').text = str(
  2116. data.get('target-is-date-format', False)).lower()
  2117. XML.SubElement(transfersset, 'flatten').text = str(
  2118. data.get('flatten', False)).lower()
  2119. XML.SubElement(transfersset, 'cleanRemote').text = str(
  2120. data.get('clean-remote', False)).lower()
  2121. if 'command' in data:
  2122. XML.SubElement(transfersset, 'execCommand').text = data['command']
  2123. if 'timeout' in data:
  2124. XML.SubElement(transfersset, 'execTimeout').text = str(data['timeout'])
  2125. if 'use-pty' in data:
  2126. XML.SubElement(transfersset, 'usePty').text = str(
  2127. data.get('use-pty', False)).lower()
  2128. XML.SubElement(inner, 'useWorkspaceInPromotion').text = 'false'
  2129. XML.SubElement(inner, 'usePromotionTimestamp').text = 'false'
  2130. XML.SubElement(delegate, 'continueOnError').text = 'false'
  2131. XML.SubElement(delegate, 'failOnError').text = str(
  2132. data.get('fail-on-error', False)).lower()
  2133. XML.SubElement(delegate, 'alwaysPublishFromMaster').text = str(
  2134. data.get('always-publish-from-master', False)).lower()
  2135. XML.SubElement(delegate, 'hostConfigurationAccess',
  2136. {'class': reference_plugin_tag, 'reference': '../..'})
  2137. return (outer, transfersset)
  2138. def cifs(registry, xml_parent, data):
  2139. """yaml: cifs
  2140. Upload files via CIFS.
  2141. Requires the Jenkins :jenkins-wiki:`Publish over CIFS Plugin
  2142. <Publish+Over+CIFS+Plugin>`.
  2143. :arg str site: name of the cifs site/share (required)
  2144. :arg str target: destination directory (required)
  2145. :arg bool target-is-date-format: whether target is a date format. If true,
  2146. raw text should be quoted (default false)
  2147. :arg bool clean-remote: should the remote directory be deleted before
  2148. transferring files (default false)
  2149. :arg str source: source path specifier (required)
  2150. :arg str excludes: excluded file pattern (default '')
  2151. :arg str remove-prefix: prefix to remove from uploaded file paths
  2152. (default '')
  2153. :arg bool fail-on-error: fail the build if an error occurs (default false).
  2154. :arg bool flatten: only create files on the server, don't create
  2155. directories (default false).
  2156. Example:
  2157. .. literalinclude:: /../../tests/publishers/fixtures/cifs001.yaml
  2158. :language: yaml
  2159. """
  2160. console_prefix = 'CIFS: '
  2161. plugin_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisherPlugin'
  2162. publisher_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisher'
  2163. transfer_tag = 'jenkins.plugins.publish__over__cifs.CifsTransfer'
  2164. plugin_reference_tag = ('jenkins.plugins.publish_over_cifs.'
  2165. 'CifsPublisherPlugin')
  2166. base_publish_over(xml_parent,
  2167. data,
  2168. console_prefix,
  2169. plugin_tag,
  2170. publisher_tag,
  2171. transfer_tag,
  2172. plugin_reference_tag)
  2173. def cigame(registry, xml_parent, data):
  2174. """yaml: cigame
  2175. This plugin introduces a game where users get points
  2176. for improving the builds.
  2177. Requires the Jenkins :jenkins-wiki:`The Continuous Integration Game plugin
  2178. <The+Continuous+Integration+Game+plugin>`.
  2179. Example:
  2180. .. literalinclude:: /../../tests/publishers/fixtures/cigame.yaml
  2181. :language: yaml
  2182. """
  2183. XML.SubElement(xml_parent, 'hudson.plugins.cigame.GamePublisher')
  2184. def sonar(registry, xml_parent, data):
  2185. """yaml: sonar
  2186. Sonar plugin support.
  2187. Requires the Jenkins `Sonar Plugin.
  2188. <http://docs.sonarqube.org/display/SONAR/\
  2189. Analyzing+with+SonarQube+Scanner+for+Jenkins>`_
  2190. :arg str jdk: JDK to use (inherited from the job if omitted). (optional)
  2191. :arg str branch: branch onto which the analysis will be posted (default '')
  2192. :arg str language: source code language (default '')
  2193. :arg str root-pom: Root POM (default 'pom.xml')
  2194. :arg bool private-maven-repo: If true, use private Maven repository.
  2195. (default false)
  2196. :arg str maven-opts: options given to maven (default '')
  2197. :arg str additional-properties: sonar analysis parameters (default '')
  2198. :arg dict skip-global-triggers:
  2199. :Triggers: * **skip-when-scm-change** (`bool`): skip analysis when
  2200. build triggered by scm (default false)
  2201. * **skip-when-upstream-build** (`bool`): skip analysis when
  2202. build triggered by an upstream build (default false)
  2203. * **skip-when-envvar-defined** (`str`): skip analysis when
  2204. the specified environment variable is set to true
  2205. (default '')
  2206. :arg str settings: Path to use as user settings.xml. It is possible to
  2207. provide a ConfigFileProvider settings file, see Example below.
  2208. (optional)
  2209. :arg str global-settings: Path to use as global settings.xml. It is
  2210. possible to provide a ConfigFileProvider settings file, see Example
  2211. below. (optional)
  2212. Requires the Jenkins :jenkins-wiki:`Config File Provider Plugin
  2213. <Config+File+Provider+Plugin>`
  2214. for the Config File Provider "settings" and "global-settings" config.
  2215. This publisher supports the post-build action exposed by the Jenkins
  2216. Sonar Plugin, which is triggering a Sonar Analysis with Maven.
  2217. Minimal Example:
  2218. .. literalinclude:: /../../tests/publishers/fixtures/sonar-minimal.yaml
  2219. :language: yaml
  2220. Full Example:
  2221. .. literalinclude:: /../../tests/publishers/fixtures/sonar-full.yaml
  2222. :language: yaml
  2223. """
  2224. sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
  2225. sonar.set('plugin', 'sonar')
  2226. if 'jdk' in data:
  2227. XML.SubElement(sonar, 'jdk').text = data['jdk']
  2228. mappings = [
  2229. ('branch', 'branch', ''),
  2230. ('language', 'language', ''),
  2231. ('root-pom', 'rootPom', 'pom.xml'),
  2232. ('private-maven-repo', 'usePrivateRepository', False),
  2233. ('maven-opts', 'mavenOpts', ''),
  2234. ('additional-properties', 'jobAdditionalProperties', '')
  2235. ]
  2236. helpers.convert_mapping_to_xml(sonar, data, mappings, fail_required=True)
  2237. if 'skip-global-triggers' in data:
  2238. data_triggers = data['skip-global-triggers']
  2239. triggers = XML.SubElement(sonar, 'triggers')
  2240. triggers_mappings = [
  2241. ('skip-when-scm-change', 'skipScmCause', False),
  2242. ('skip-when-upstream-build', 'skipUpstreamCause', False),
  2243. ('skip-when-envvar-defined', 'envVar', '')
  2244. ]
  2245. helpers.convert_mapping_to_xml(
  2246. triggers, data_triggers, triggers_mappings, fail_required=True)
  2247. helpers.config_file_provider_settings(sonar, data)
  2248. def performance(registry, xml_parent, data):
  2249. """yaml: performance
  2250. Publish performance test results from jmeter and junit.
  2251. Requires the Jenkins :jenkins-wiki:`Performance Plugin
  2252. <Performance+Plugin>`.
  2253. :arg int failed-threshold: Specify the error percentage threshold that
  2254. set the build failed. A negative value means don't use this threshold
  2255. (default 0)
  2256. :arg int unstable-threshold: Specify the error percentage threshold that
  2257. set the build unstable. A negative value means don't use this threshold
  2258. (default 0)
  2259. :arg str unstable-response-time-threshold: Average response time threshold
  2260. (default '')
  2261. :arg float failed-threshold-positive: Maximum failed percentage for build
  2262. comparison (default 0.0)
  2263. :arg float failed-threshold-negative: Minimum failed percentage for build
  2264. comparison (default 0.0)
  2265. :arg float unstable-threshold-positive: Maximum unstable percentage for
  2266. build comparison (default 0.0)
  2267. :arg float unstable-threshold-negative: Minimum unstable percentage for
  2268. build comparison (default 0.0)
  2269. :arg int nth-build-number: Build number for build comparison (default 0)
  2270. :arg bool mode-relative-thresholds: Relative threshold mode (default false)
  2271. :arg str config-type: Compare based on (default 'ART')
  2272. :config-type values:
  2273. * **ART** -- Average Response Time
  2274. * **MRT** -- Median Response Time
  2275. * **PRT** -- Percentile Response Time
  2276. :arg bool mode-of-threshold: Mode of threshold, true for relative threshold
  2277. and false for error threshold (default false)
  2278. :arg bool fail-build: Fail build when result files are not present
  2279. (default false)
  2280. :arg bool compare-build-previous: Compare with previous build
  2281. (default false)
  2282. :arg bool mode-performance-per-test-case: Performance Per Test Case Mode
  2283. (default true)
  2284. :arg bool mode-thoughput: Show Throughput Chart (default false)
  2285. :arg dict report:
  2286. :(jmeter or junit): (`dict` or `str`): Specify a custom report file
  2287. (optional; jmeter default \**/*.jtl, junit default **/TEST-\*.xml)
  2288. Minimal Example:
  2289. .. literalinclude::
  2290. /../../tests/publishers/fixtures/performance-minimal.yaml
  2291. :language: yaml
  2292. Full Example:
  2293. .. literalinclude::
  2294. /../../tests/publishers/fixtures/performance-full.yaml
  2295. :language: yaml
  2296. """
  2297. perf = XML.SubElement(xml_parent, 'hudson.plugins.performance.'
  2298. 'PerformancePublisher')
  2299. perf.set('plugin', 'performance')
  2300. types = ['ART', 'MRT', 'PRT']
  2301. mappings = [
  2302. ('failed-threshold', 'errorFailedThreshold', 0),
  2303. ('unstable-threshold', 'errorUnstableThreshold', 0),
  2304. ('unstable-response-time-threshold',
  2305. 'errorUnstableResponseTimeThreshold',
  2306. ''),
  2307. ('failed-threshold-positive',
  2308. 'relativeFailedThresholdPositive',
  2309. '0.0'),
  2310. ('failed-threshold-negative',
  2311. 'relativeFailedThresholdNegative',
  2312. '0.0'),
  2313. ('unstable-threshold-positive',
  2314. 'relativeUnstableThresholdPositive',
  2315. '0.0'),
  2316. ('unstable-threshold-negative',
  2317. 'relativeUnstableThresholdNegative',
  2318. '0.0'),
  2319. ('nth-build-number', 'nthBuildNumber', 0),
  2320. ('mode-relative-thresholds', 'modeRelativeThresholds', False),
  2321. ('config-type', 'configType', 'ART', types),
  2322. ('mode-of-threshold', 'modeOfThreshold', False),
  2323. ('fail-build', 'failBuildIfNoResultFile', False),
  2324. ('compare-build-previous', 'compareBuildPrevious', False),
  2325. ('mode-performance-per-test-case', 'modePerformancePerTestCase', True),
  2326. ('mode-thoughput', 'modeThroughput', False)
  2327. ]
  2328. helpers.convert_mapping_to_xml(perf, data, mappings, fail_required=True)
  2329. parsers = XML.SubElement(perf, 'parsers')
  2330. if 'report' in data:
  2331. for item in data['report']:
  2332. if isinstance(item, dict):
  2333. item_name = next(iter(item.keys()))
  2334. item_values = item.get(item_name, None)
  2335. if item_name == 'jmeter':
  2336. jmhold = XML.SubElement(parsers, 'hudson.plugins.'
  2337. 'performance.'
  2338. 'JMeterParser')
  2339. XML.SubElement(jmhold, 'glob').text = str(item_values)
  2340. elif item_name == 'junit':
  2341. juhold = XML.SubElement(parsers, 'hudson.plugins.'
  2342. 'performance.'
  2343. 'JUnitParser')
  2344. XML.SubElement(juhold, 'glob').text = str(item_values)
  2345. else:
  2346. raise JenkinsJobsException("You have not specified jmeter "
  2347. "or junit, or you have "
  2348. "incorrectly assigned the key "
  2349. "value.")
  2350. elif isinstance(item, str):
  2351. if item == 'jmeter':
  2352. jmhold = XML.SubElement(parsers, 'hudson.plugins.'
  2353. 'performance.'
  2354. 'JMeterParser')
  2355. XML.SubElement(jmhold, 'glob').text = '**/*.jtl'
  2356. elif item == 'junit':
  2357. juhold = XML.SubElement(parsers, 'hudson.plugins.'
  2358. 'performance.'
  2359. 'JUnitParser')
  2360. XML.SubElement(juhold, 'glob').text = '**/TEST-*.xml'
  2361. else:
  2362. raise JenkinsJobsException("You have not specified jmeter "
  2363. "or junit, or you have "
  2364. "incorrectly assigned the key "
  2365. "value.")
  2366. def join_trigger(registry, xml_parent, data):
  2367. """yaml: join-trigger
  2368. Trigger a job after all the immediate downstream jobs have completed.
  2369. Requires the Jenkins :jenkins-wiki:`Join Plugin <Join+Plugin>`.
  2370. :arg bool even-if-unstable: if true jobs will trigger even if some
  2371. downstream jobs are marked as unstable (default false)
  2372. :arg list projects: list of projects to trigger
  2373. :arg list publishers: list of triggers from publishers module that
  2374. defines projects that need to be triggered
  2375. Example:
  2376. .. literalinclude::
  2377. /../../tests/publishers/fixtures/join-trigger001.yaml
  2378. :language: yaml
  2379. """
  2380. jointrigger = XML.SubElement(xml_parent, 'join.JoinTrigger')
  2381. joinProjectsText = ','.join(data.get('projects', ['']))
  2382. XML.SubElement(jointrigger, 'joinProjects').text = joinProjectsText
  2383. publishers = XML.SubElement(jointrigger, 'joinPublishers')
  2384. for pub in data.get('publishers', []):
  2385. for edited_node in create_publishers(registry, pub):
  2386. publishers.append(edited_node)
  2387. unstable = str(data.get('even-if-unstable', 'false')).lower()
  2388. XML.SubElement(jointrigger, 'evenIfDownstreamUnstable').text = unstable
  2389. def jabber(registry, xml_parent, data):
  2390. """yaml: jabber
  2391. Integrates Jenkins with the Jabber/XMPP instant messaging protocol
  2392. Requires the Jenkins :jenkins-wiki:`Jabber Plugin <Jabber+Plugin>`.
  2393. :arg bool notify-on-build-start: Whether to send notifications
  2394. to channels when a build starts (default false)
  2395. :arg bool notify-scm-committers: Whether to send notifications
  2396. to the users that are suspected of having broken this build
  2397. (default false)
  2398. :arg bool notify-scm-culprits: Also send notifications to 'culprits'
  2399. from previous unstable/failed builds (default false)
  2400. :arg bool notify-upstream-committers: Whether to send notifications to
  2401. upstream committers if no committers were found for a broken build
  2402. (default false)
  2403. :arg bool notify-scm-fixers: Whether to send notifications to the users
  2404. that have fixed a broken build (default false)
  2405. :arg list group-targets: List of group targets to notify
  2406. :arg list individual-targets: List of individual targets to notify
  2407. :arg dict strategy: When to send notifications (default all)
  2408. :strategy values:
  2409. * **all** -- Always
  2410. * **failure** -- On any failure
  2411. * **failure-fixed** -- On failure and fixes
  2412. * **new-failure-fixed** -- On new failure and fixes
  2413. * **change** -- Only on state change
  2414. :arg dict message: Channel notification message (default summary-scm)
  2415. :message values:
  2416. * **summary-scm** -- Summary + SCM changes
  2417. * **summary** -- Just summary
  2418. * **summary-build** -- Summary and build parameters
  2419. * **summary-scm-fail** -- Summary, SCM changes, and failed tests
  2420. Minimal Example:
  2421. .. literalinclude::
  2422. /../../tests/publishers/fixtures/jabber-minimal.yaml
  2423. :language: yaml
  2424. Full Example:
  2425. .. literalinclude:: /../../tests/publishers/fixtures/jabber-full.yaml
  2426. :language: yaml
  2427. """
  2428. j = XML.SubElement(xml_parent, 'hudson.plugins.jabber.im.transport.'
  2429. 'JabberPublisher')
  2430. j.set('plugin', 'jabber')
  2431. t = XML.SubElement(j, 'targets')
  2432. if 'group-targets' in data:
  2433. for group in data['group-targets']:
  2434. gcimt = XML.SubElement(t, 'hudson.plugins.im.'
  2435. 'GroupChatIMMessageTarget')
  2436. gcimt.set('plugin', 'instant-messaging')
  2437. XML.SubElement(gcimt, 'name').text = group
  2438. XML.SubElement(gcimt, 'notificationOnly').text = 'false'
  2439. if 'individual-targets' in data:
  2440. for individual in data['individual-targets']:
  2441. dimt = XML.SubElement(t, 'hudson.plugins.im.'
  2442. 'DefaultIMMessageTarget')
  2443. dimt.set('plugin', 'instant-messaging')
  2444. XML.SubElement(dimt, 'value').text = individual
  2445. strategy = data.get('strategy', 'all')
  2446. strategydict = {'all': 'ALL',
  2447. 'failure': 'ANY_FAILURE',
  2448. 'failure-fixed': 'FAILURE_AND_FIXED',
  2449. 'new-failure-fixed': 'NEW_FAILURE_AND_FIXED',
  2450. 'change': 'STATECHANGE_ONLY'}
  2451. if strategy not in strategydict:
  2452. raise JenkinsJobsException("Strategy entered is not valid, must be " +
  2453. "one of: all, failure, failure-fixed, or "
  2454. "change")
  2455. XML.SubElement(j, 'strategy').text = strategydict[strategy]
  2456. mappings = [
  2457. ('notify-on-build-start', 'notifyOnBuildStart', False),
  2458. ('notify-scm-committers', 'notifySuspects', False),
  2459. ('notify-scm-culprits', 'notifyCulprits', False),
  2460. ('notify-scm-fixers', 'notifyFixers', False),
  2461. ('notify-upstream-committers', 'notifyUpstreamCommitters', False)
  2462. ]
  2463. helpers.convert_mapping_to_xml(j, data, mappings, fail_required=True)
  2464. message = data.get('message', 'summary-scm')
  2465. messagedict = {'summary-scm': 'DefaultBuildToChatNotifier',
  2466. 'summary': 'SummaryOnlyBuildToChatNotifier',
  2467. 'summary-build': 'BuildParametersBuildToChatNotifier',
  2468. 'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
  2469. if message not in messagedict:
  2470. raise JenkinsJobsException("Message entered is not valid, must be one "
  2471. "of: summary-scm, summary, summary-build "
  2472. "or summary-scm-fail")
  2473. XML.SubElement(j, 'buildToChatNotifier', {
  2474. 'class': 'hudson.plugins.im.build_notify.' + messagedict[message]})
  2475. XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS'
  2476. def workspace_cleanup(registry, xml_parent, data):
  2477. """yaml: workspace-cleanup (post-build)
  2478. Requires the Jenkins :jenkins-wiki:`Workspace Cleanup Plugin
  2479. <Workspace+Cleanup+Plugin>`.
  2480. The pre-build workspace-cleanup is available as a wrapper.
  2481. :arg list include: list of files to be included
  2482. :arg list exclude: list of files to be excluded
  2483. :arg bool dirmatch: Apply pattern to directories too (default false)
  2484. :arg list clean-if: clean depending on build status
  2485. :clean-if values:
  2486. * **success** (`bool`) (default true)
  2487. * **unstable** (`bool`) (default true)
  2488. * **failure** (`bool`) (default true)
  2489. * **aborted** (`bool`) (default true)
  2490. * **not-built** (`bool`) (default true)
  2491. :arg bool fail-build: Fail the build if the cleanup fails (default true)
  2492. :arg bool clean-parent: Cleanup matrix parent workspace (default false)
  2493. :arg str external-deletion-command: external deletion command to run
  2494. against files and directories
  2495. Minimal Example:
  2496. .. literalinclude::
  2497. /../../tests/publishers/fixtures/workspace-cleanup-minimal.yaml
  2498. :language: yaml
  2499. Full Example:
  2500. .. literalinclude::
  2501. /../../tests/publishers/fixtures/workspace-cleanup-full.yaml
  2502. :language: yaml
  2503. """
  2504. p = XML.SubElement(xml_parent,
  2505. 'hudson.plugins.ws__cleanup.WsCleanup')
  2506. p.set("plugin", "ws-cleanup")
  2507. if "include" in data or "exclude" in data:
  2508. patterns = XML.SubElement(p, 'patterns')
  2509. for inc in data.get("include", []):
  2510. ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
  2511. XML.SubElement(ptrn, 'pattern').text = inc
  2512. XML.SubElement(ptrn, 'type').text = "INCLUDE"
  2513. for exc in data.get("exclude", []):
  2514. ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
  2515. XML.SubElement(ptrn, 'pattern').text = exc
  2516. XML.SubElement(ptrn, 'type').text = "EXCLUDE"
  2517. mappings = [
  2518. ('dirmatch', 'deleteDirs', False),
  2519. ('clean-parent', 'cleanupMatrixParent', False),
  2520. ('external-deletion-command', 'externalDelete', '')
  2521. ]
  2522. helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
  2523. mask = [('success', 'cleanWhenSuccess'),
  2524. ('unstable', 'cleanWhenUnstable'),
  2525. ('failure', 'cleanWhenFailure'),
  2526. ('not-built', 'cleanWhenNotBuilt'),
  2527. ('aborted', 'cleanWhenAborted')]
  2528. clean = data.get('clean-if', [])
  2529. cdict = dict()
  2530. for d in clean:
  2531. cdict.update(d)
  2532. for k, v in mask:
  2533. XML.SubElement(p, v).text = str(cdict.pop(k, True)).lower()
  2534. if len(cdict) > 0:
  2535. raise ValueError('clean-if must be one of: %r' % list(mask.keys()))
  2536. if str(data.get("fail-build", False)).lower() == 'false':
  2537. XML.SubElement(p, 'notFailBuild').text = 'true'
  2538. else:
  2539. XML.SubElement(p, 'notFailBuild').text = 'false'
  2540. def maven_deploy(registry, xml_parent, data):
  2541. """yaml: maven-deploy
  2542. Deploy artifacts to Maven repository.
  2543. :arg str id: Repository ID
  2544. :arg str url: Repository URL (optional)
  2545. :arg bool unique-version: Assign unique versions to snapshots
  2546. (default true)
  2547. :arg bool deploy-unstable: Deploy even if the build is unstable
  2548. (default false)
  2549. :arg str release-env-var: If the given variable name is set to "true",
  2550. the deploy steps are skipped. (optional)
  2551. Example:
  2552. .. literalinclude:: /../../tests/publishers/fixtures/maven-deploy001.yaml
  2553. :language: yaml
  2554. """
  2555. p = XML.SubElement(xml_parent, 'hudson.maven.RedeployPublisher')
  2556. if 'id' in data:
  2557. XML.SubElement(p, 'id').text = data['id']
  2558. if 'url' in data:
  2559. XML.SubElement(p, 'url').text = data['url']
  2560. XML.SubElement(p, 'uniqueVersion').text = str(
  2561. data.get('unique-version', True)).lower()
  2562. XML.SubElement(p, 'evenIfUnstable').text = str(
  2563. data.get('deploy-unstable', False)).lower()
  2564. if 'release-env-var' in data:
  2565. XML.SubElement(p, 'releaseEnvVar').text = data['release-env-var']
  2566. def artifactory(registry, xml_parent, data):
  2567. """yaml: artifactory
  2568. Uses/requires the Artifactory plugin to deploy artifacts to
  2569. Artifactory Server.
  2570. Requires the Jenkins :jenkins-wiki:`Artifactory Plugin
  2571. <Artifactory+Plugin>`.
  2572. :arg str url: Artifactory server url (default '')
  2573. :arg str name: Artifactory user with permissions use for
  2574. connected to the selected Artifactory Server (default '')
  2575. :arg str release-repo-key: Release repository name (default '')
  2576. :arg str snapshot-repo-key: Snapshots repository name (default '')
  2577. :arg bool publish-build-info: Push build metadata with artifacts
  2578. (default false)
  2579. :arg bool discard-old-builds:
  2580. Remove older build info from Artifactory (default false)
  2581. :arg bool discard-build-artifacts:
  2582. Remove older build artifacts from Artifactory (default false)
  2583. :arg bool even-if-unstable: Deploy artifacts even when the build
  2584. is unstable (default false)
  2585. :arg bool run-checks: Run automatic license scanning check after the
  2586. build is complete (default false)
  2587. :arg bool include-publish-artifacts: Include the build's published
  2588. module artifacts in the license violation checks if they are
  2589. also used as dependencies for other modules in this build
  2590. (default false)
  2591. :arg bool pass-identified-downstream: When true, a build parameter
  2592. named ARTIFACTORY_BUILD_ROOT with a value of
  2593. ${JOB_NAME}-${BUILD_NUMBER} will be sent to downstream builds
  2594. (default false)
  2595. :arg bool license-auto-discovery: Tells Artifactory not to try
  2596. and automatically analyze and tag the build's dependencies
  2597. with license information upon deployment (default true)
  2598. :arg bool enable-issue-tracker-integration: When the Jenkins
  2599. JIRA plugin is enabled, synchronize information about JIRA
  2600. issues to Artifactory and attach issue information to build
  2601. artifacts (default false)
  2602. :arg bool aggregate-build-issues: When the Jenkins JIRA plugin
  2603. is enabled, include all issues from previous builds up to the
  2604. latest build status defined in "Aggregation Build Status"
  2605. (default false)
  2606. :arg bool allow-promotion-of-non-staged-builds: The build
  2607. promotion operation will be available to all successful builds
  2608. instead of only staged ones (default false)
  2609. :arg bool filter-excluded-artifacts-from-build: Add the excluded
  2610. files to the excludedArtifacts list and remove them from the
  2611. artifacts list in the build info (default false)
  2612. :arg str scopes: A list of dependency scopes/configurations to run
  2613. license violation checks on. If left empty all dependencies from
  2614. all scopes will be checked (default '')
  2615. :arg str violation-recipients: Recipients that need to be notified
  2616. of license violations in the build info (default '')
  2617. :arg list matrix-params: Semicolon-separated list of properties to
  2618. attach to all deployed artifacts in addition to the default ones:
  2619. build.name, build.number, and vcs.revision (default [])
  2620. :arg str black-duck-app-name: The existing Black Duck Code Center
  2621. application name (default '')
  2622. :arg str black-duck-app-version: The existing Black Duck Code Center
  2623. application version (default '')
  2624. :arg str black-duck-report-recipients: Recipients that will be emailed
  2625. a report after the automatic Black Duck Code Center compliance checks
  2626. finished (default '')
  2627. :arg str black-duck-scopes: A list of dependency scopes/configurations
  2628. to run Black Duck Code Center compliance checks on. If left empty
  2629. all dependencies from all scopes will be checked (default '')
  2630. :arg bool black-duck-run-checks: Automatic Black Duck Code Center
  2631. compliance checks will occur after the build completes
  2632. (default false)
  2633. :arg bool black-duck-include-published-artifacts: Include the build's
  2634. published module artifacts in the license violation checks if they
  2635. are also used as dependencies for other modules in this build
  2636. (default false)
  2637. :arg bool auto-create-missing-component-requests: Auto create
  2638. missing components in Black Duck Code Center application after
  2639. the build is completed and deployed in Artifactory
  2640. (default true)
  2641. :arg bool auto-discard-stale-component-requests: Auto discard
  2642. stale components in Black Duck Code Center application after
  2643. the build is completed and deployed in Artifactory
  2644. (default true)
  2645. :arg bool deploy-artifacts: Push artifacts to the Artifactory
  2646. Server. Use deployment-include-patterns and
  2647. deployment-exclude-patterns to filter deploy artifacts. (default true)
  2648. :arg list deployment-include-patterns: New line or comma separated mappings
  2649. of build artifacts to published artifacts. Supports Ant-style wildcards
  2650. mapping to target directories. E.g.: */*.zip=>dir (default [])
  2651. :arg list deployment-exclude-patterns: New line or comma separated patterns
  2652. for excluding artifacts from deployment to Artifactory (default [])
  2653. :arg bool env-vars-include: Include all environment variables
  2654. accessible by the build process. Jenkins-specific env variables
  2655. are always included. Use env-vars-include-patterns and
  2656. env-vars-exclude-patterns to filter variables to publish,
  2657. (default false)
  2658. :arg list env-vars-include-patterns: Comma or space-separated list of
  2659. environment variables that will be included as part of the published
  2660. build info. Environment variables may contain the * and the ? wildcards
  2661. (default [])
  2662. :arg list env-vars-exclude-patterns: Comma or space-separated list of
  2663. environment variables that will be excluded from the published
  2664. build info (default [])
  2665. Example:
  2666. .. literalinclude:: /../../tests/publishers/fixtures/artifactory01.yaml
  2667. .. literalinclude:: /../../tests/publishers/fixtures/artifactory02.yaml
  2668. """
  2669. artifactory = XML.SubElement(
  2670. xml_parent, 'org.jfrog.hudson.ArtifactoryRedeployPublisher')
  2671. # optional_props
  2672. helpers.artifactory_optional_props(artifactory, data, 'publishers')
  2673. XML.SubElement(artifactory, 'matrixParams').text = ','.join(
  2674. data.get('matrix-params', []))
  2675. # details
  2676. details = XML.SubElement(artifactory, 'details')
  2677. helpers.artifactory_common_details(details, data)
  2678. mapping = [
  2679. ('release-repo-key', 'repositoryKey', ''),
  2680. ('snapshot-repo-key', 'snapshotsRepositoryKey', ''),
  2681. ]
  2682. helpers.convert_mapping_to_xml(details, data, mapping, fail_required=True)
  2683. plugin = XML.SubElement(details, 'stagingPlugin')
  2684. XML.SubElement(plugin, 'pluginName').text = 'None'
  2685. # artifactDeploymentPatterns
  2686. helpers.artifactory_deployment_patterns(artifactory, data)
  2687. # envVarsPatterns
  2688. helpers.artifactory_env_vars_patterns(artifactory, data)
  2689. def test_fairy(registry, xml_parent, data):
  2690. """yaml: test-fairy
  2691. This plugin helps you to upload Android APKs or iOS IPA files to
  2692. www.testfairy.com.
  2693. Requires the Jenkins :jenkins-wiki:`Test Fairy Plugin
  2694. <TestFairy+Plugin>`.
  2695. :arg str platform: Select platform to upload to, **android** or **ios**
  2696. (required)
  2697. Android Only:
  2698. :arg str proguard-file: Path to Proguard file. Path of mapping.txt from
  2699. your proguard output directory. (default '')
  2700. :arg str storepass: Password for the keystore (default android)
  2701. :arg str alias: alias for key (default androiddebugkey)
  2702. :arg str keypass: password for the key (default '')
  2703. :arg str keystorepath: Path to Keystore file (required)
  2704. IOS Only:
  2705. :arg str dSYM-file: Path to .dSYM.zip file (default '')
  2706. All:
  2707. :arg str apikey: TestFairy API_KEY. Find it in your TestFairy account
  2708. settings (required)
  2709. :arg str appfile: Path to App file (.apk) or (.ipa). For example:
  2710. $WORKSPACE/[YOUR_FILE_NAME].apk or full path to the apk file.
  2711. (required)
  2712. :arg str tester-groups: Tester groups to notify (default '')
  2713. :arg bool notify-testers: Send email with changelogs to testers
  2714. (default false)
  2715. :arg bool autoupdate: Automatic update (default false)
  2716. :arg str max-duration: Duration of the session (default 10m)
  2717. :max-duration values:
  2718. * **10m**
  2719. * **60m**
  2720. * **300m**
  2721. * **1440m**
  2722. :arg bool record-on-background: Record on background (default false)
  2723. :arg bool data-only-wifi: Record data only in wifi (default false)
  2724. :arg bool video-enabled: Record video (default true)
  2725. :arg int screenshot-interval: Time interval between screenshots
  2726. (default 1)
  2727. :screenshot-interval values:
  2728. * **1**
  2729. * **2**
  2730. * **5**
  2731. :arg str video-quality: Video quality (default high)
  2732. :video-quality values:
  2733. * **high**
  2734. * **medium**
  2735. * **low**
  2736. :arg bool cpu: Enable CPU metrics (default true)
  2737. :arg bool memory: Enable memory metrics (default true)
  2738. :arg bool logs: Enable logs metrics (default true)
  2739. :arg bool network: Enable network metrics (default false)
  2740. :arg bool phone-signal: Enable phone signal metrics (default false)
  2741. :arg bool wifi: Enable wifi metrics (default false)
  2742. :arg bool gps: Enable gps metrics (default false)
  2743. :arg bool battery: Enable battery metrics (default false)
  2744. :arg bool opengl: Enable opengl metrics (default false)
  2745. Example:
  2746. .. literalinclude::
  2747. /../../tests/publishers/fixtures/test-fairy-android-minimal.yaml
  2748. :language: yaml
  2749. .. literalinclude::
  2750. /../../tests/publishers/fixtures/test-fairy-android001.yaml
  2751. :language: yaml
  2752. .. literalinclude::
  2753. /../../tests/publishers/fixtures/test-fairy-ios-minimal.yaml
  2754. :language: yaml
  2755. .. literalinclude::
  2756. /../../tests/publishers/fixtures/test-fairy-ios001.yaml
  2757. :language: yaml
  2758. """
  2759. platform = data.get('platform')
  2760. valid_platforms = ['android', 'ios']
  2761. if 'platform' not in data:
  2762. raise MissingAttributeError('platform')
  2763. if platform == 'android':
  2764. root = XML.SubElement(
  2765. xml_parent,
  2766. 'org.jenkinsci.plugins.testfairy.TestFairyAndroidRecorder')
  2767. helpers.test_fairy_common(root, data)
  2768. mappings = [
  2769. ('proguard-file', 'mappingFile', ''),
  2770. ('keystorepath', 'keystorePath', None),
  2771. ('storepass', 'storepass', 'android'),
  2772. ('alias', 'alias', 'androiddebugkey'),
  2773. ('keypass', 'keypass', '')]
  2774. helpers.convert_mapping_to_xml(
  2775. root, data, mappings, fail_required=True)
  2776. elif platform == 'ios':
  2777. root = XML.SubElement(
  2778. xml_parent, 'org.jenkinsci.plugins.testfairy.TestFairyIosRecorder')
  2779. helpers.test_fairy_common(root, data)
  2780. mappings = [('dSYM-file', 'mappingFile', '')]
  2781. helpers.convert_mapping_to_xml(
  2782. root, data, mappings, fail_required=True)
  2783. else:
  2784. raise InvalidAttributeError('platform', platform, valid_platforms)
  2785. def text_finder(registry, xml_parent, data):
  2786. """yaml: text-finder
  2787. This plugin lets you search keywords in the files you specified and
  2788. additionally check build status
  2789. Requires the Jenkins :jenkins-wiki:`Text-finder Plugin
  2790. <Text-finder+Plugin>`.
  2791. :arg str regexp: Specify a regular expression (required)
  2792. :arg str fileset: Specify the path to search (optional)
  2793. :arg bool also-check-console-output:
  2794. Search the console output (default false)
  2795. :arg bool succeed-if-found:
  2796. Force a build to succeed if a string was found (default false)
  2797. :arg bool unstable-if-found:
  2798. Set build unstable instead of failing the build (default false)
  2799. Example:
  2800. .. literalinclude:: /../../tests/publishers/fixtures/text-finder001.yaml
  2801. :language: yaml
  2802. """
  2803. finder = XML.SubElement(xml_parent,
  2804. 'hudson.plugins.textfinder.TextFinderPublisher')
  2805. finder.set('plugin', 'text-finder')
  2806. if ('fileset' in data):
  2807. XML.SubElement(finder, 'fileSet').text = data['fileset']
  2808. mappings = [
  2809. ('regexp', 'regexp', None),
  2810. ('also-check-console-output', 'alsoCheckConsoleOutput', False),
  2811. ('succeed-if-found', 'succeedIfFound', False),
  2812. ('unstable-if-found', 'unstableIfFound', False)
  2813. ]
  2814. helpers.convert_mapping_to_xml(finder, data, mappings, fail_required=True)
  2815. def html_publisher(registry, xml_parent, data):
  2816. """yaml: html-publisher
  2817. This plugin publishes HTML reports.
  2818. Requires the Jenkins :jenkins-wiki:`HTML Publisher Plugin
  2819. <HTML+Publisher+Plugin>`.
  2820. :arg str name: Report name (required)
  2821. :arg str dir: HTML directory to archive (required)
  2822. :arg str files: Specify the pages to display (required)
  2823. :arg bool keep-all: keep HTML reports for each past build (default false)
  2824. :arg bool allow-missing: Allow missing HTML reports (default false)
  2825. :arg bool link-to-last-build: If this and 'keep-all' both are true, it
  2826. publishes the link on project level even if build failed.
  2827. (default false)
  2828. Example:
  2829. .. literalinclude:: /../../tests/publishers/fixtures/html-publisher001.yaml
  2830. :language: yaml
  2831. """
  2832. reporter = XML.SubElement(xml_parent, 'htmlpublisher.HtmlPublisher')
  2833. targets = XML.SubElement(reporter, 'reportTargets')
  2834. ptarget = XML.SubElement(targets, 'htmlpublisher.HtmlPublisherTarget')
  2835. mapping = [
  2836. ('name', 'reportName', None),
  2837. ('dir', 'reportDir', None),
  2838. ('files', 'reportFiles', None),
  2839. ('link-to-last-build', 'alwaysLinkToLastBuild', False),
  2840. ('keep-all', 'keepAll', False),
  2841. ('allow-missing', 'allowMissing', False),
  2842. ]
  2843. helpers.convert_mapping_to_xml(ptarget, data, mapping, fail_required=True)
  2844. XML.SubElement(ptarget, 'wrapperName').text = "htmlpublisher-wrapper.html"
  2845. def rich_text_publisher(registry, xml_parent, data):
  2846. """yaml: rich-text-publisher
  2847. This plugin puts custom rich text message to the Build pages and Job main
  2848. page.
  2849. Requires the Jenkins :jenkins-wiki:`Rich Text Publisher Plugin
  2850. <Rich+Text+Publisher+Plugin>`.
  2851. :arg str stable-text: The stable text (required)
  2852. :arg str unstable-text: The unstable text if different from stable
  2853. (default '')
  2854. :arg bool unstable-as-stable: The same text block is used for stable and
  2855. unstable builds (default true)
  2856. :arg str failed-text: The failed text if different from stable (default '')
  2857. :arg bool failed-as-stable: The same text block is used for stable and
  2858. failed builds (default true)
  2859. :arg str parser-name: HTML, Confluence or WikiText (default 'WikiText')
  2860. Minimal Example:
  2861. .. literalinclude:: /../../tests/publishers/fixtures/richtext-minimal.yaml
  2862. :language: yaml
  2863. Full Example:
  2864. .. literalinclude::
  2865. /../../tests/publishers/fixtures/richtext-full.yaml
  2866. :language: yaml
  2867. """
  2868. parsers = ['HTML', 'Confluence', 'WikiText']
  2869. reporter = XML.SubElement(
  2870. xml_parent,
  2871. 'org.korosoft.jenkins.plugin.rtp.RichTextPublisher')
  2872. reporter.set('plugin', 'rich-text-publisher-plugin')
  2873. mappings = [
  2874. ('stable-text', 'stableText', None),
  2875. ('unstable-text', 'unstableText', ''),
  2876. ('failed-text', 'failedText', ''),
  2877. ('unstable-as-stable', 'unstableAsStable', True),
  2878. ('failed-as-stable', 'failedAsStable', True),
  2879. ('parser-name', 'parserName', 'WikiText', parsers)
  2880. ]
  2881. helpers.convert_mapping_to_xml(
  2882. reporter, data, mappings, fail_required=True)
  2883. def tap(registry, xml_parent, data):
  2884. """yaml: tap
  2885. Adds support to TAP test result files
  2886. Requires the Jenkins :jenkins-wiki:`TAP Plugin <TAP+Plugin>`.
  2887. :arg str results: TAP test result files (required)
  2888. :arg bool fail-if-no-results: Fail if no result (default false)
  2889. :arg bool failed-tests-mark-build-as-failure:
  2890. Mark build as failure if test fails (default false)
  2891. :arg bool output-tap-to-console: Output tap to console (default true)
  2892. :arg bool enable-subtests: Enable subtests (default true)
  2893. :arg bool discard-old-reports: Discard old reports (default false)
  2894. :arg bool todo-is-failure: Handle TODO's as failures (default true)
  2895. :arg bool include-comment-diagnostics: Include comment diagnostics (#) in
  2896. the results table (>=1.12) (default false)
  2897. :arg bool validate-tests: Validate number of tests (>=1.13) (default false)
  2898. :arg bool plan-required: TAP plan required? (>=1.17) (default true)
  2899. :arg bool verbose: Print a message for each TAP stream file (>=1.17)
  2900. (default true)
  2901. :arg bool show-only-failures: show only test failures (>=1.17)
  2902. (default false)
  2903. Full Example:
  2904. .. literalinclude:: /../../tests/publishers/fixtures/tap-full.yaml
  2905. :language: yaml
  2906. Minimal Example:
  2907. .. literalinclude:: /../../tests/publishers/fixtures/tap-minimal.yaml
  2908. :language: yaml
  2909. """
  2910. tap = XML.SubElement(xml_parent, 'org.tap4j.plugin.TapPublisher')
  2911. tap.set('plugin', 'tap')
  2912. mappings = [
  2913. ('results', 'testResults', None),
  2914. ('fail-if-no-results', 'failIfNoResults', False),
  2915. ('failed-tests-mark-build-as-failure',
  2916. 'failedTestsMarkBuildAsFailure',
  2917. False),
  2918. ('output-tap-to-console', 'outputTapToConsole', True),
  2919. ('enable-subtests', 'enableSubtests', True),
  2920. ('discard-old-reports', 'discardOldReports', False),
  2921. ('todo-is-failure', 'todoIsFailure', True),
  2922. ('include-comment-diagnostics', 'includeCommentDiagnostics', False),
  2923. ('validate-tests', 'validateNumberOfTests', False),
  2924. ('plan-required', 'planRequired', True),
  2925. ('verbose', 'verbose', True),
  2926. ('show-only-failures', 'showOnlyFailures', False),
  2927. ]
  2928. helpers.convert_mapping_to_xml(tap, data, mappings, fail_required=True)
  2929. def post_tasks(registry, xml_parent, data):
  2930. """yaml: post-tasks
  2931. Adds support to post build task plugin
  2932. Requires the Jenkins :jenkins-wiki:`Post Build Task plugin
  2933. <Post+build+task>`.
  2934. :arg dict task: Post build task definition
  2935. :arg list task[matches]: list of matches when to run the task
  2936. :arg dict task[matches][*]: match definition
  2937. :arg str task[matches][*][log-text]: text to match against the log
  2938. :arg str task[matches][*][operator]: operator to apply with the next match
  2939. :task[matches][*][operator] values (default 'AND'):
  2940. * **AND**
  2941. * **OR**
  2942. :arg bool task[escalate-status]: Escalate the task status to the job
  2943. (default 'false')
  2944. :arg bool task[run-if-job-successful]: Run only if the job was successful
  2945. (default 'false')
  2946. :arg str task[script]: Shell script to run (default '')
  2947. Example:
  2948. .. literalinclude:: /../../tests/publishers/fixtures/post-tasks001.yaml
  2949. :language: yaml
  2950. """
  2951. pb_xml = XML.SubElement(xml_parent,
  2952. 'hudson.plugins.postbuildtask.PostbuildTask')
  2953. tasks_xml = XML.SubElement(pb_xml, 'tasks')
  2954. for task in data:
  2955. task_xml = XML.SubElement(
  2956. tasks_xml,
  2957. 'hudson.plugins.postbuildtask.TaskProperties')
  2958. matches_xml = XML.SubElement(task_xml, 'logTexts')
  2959. for match in task.get('matches', []):
  2960. lt_xml = XML.SubElement(
  2961. matches_xml,
  2962. 'hudson.plugins.postbuildtask.LogProperties')
  2963. XML.SubElement(lt_xml, 'logText').text = str(
  2964. match.get('log-text', False) or '')
  2965. XML.SubElement(lt_xml, 'operator').text = str(
  2966. match.get('operator', 'AND')).upper()
  2967. mapping = [
  2968. ('escalate-status', 'EscalateStatus', False),
  2969. ('run-if-job-successful', 'RunIfJobSuccessful', False),
  2970. ('script', 'script', '')]
  2971. helpers.convert_mapping_to_xml(task_xml,
  2972. task, mapping, fail_required=True)
  2973. def postbuildscript(registry, xml_parent, data):
  2974. """yaml: postbuildscript
  2975. Executes additional builders, script or Groovy after the build is
  2976. complete.
  2977. Requires the Jenkins :jenkins-wiki:`Post Build Script plugin
  2978. <PostBuildScript+Plugin>`.
  2979. :arg list generic-script: Series of Batch/Shell scripts to to run
  2980. :generic-script: * **file-path** (`str`) - Path to Batch/Shell scripts
  2981. * **role** (`str`) - Execute scripts on. One of
  2982. MASTER / SLAVE / BOTH. (default 'BOTH')
  2983. * **build-on** (`list`) - Build statuses which trigger
  2984. the scripts. Valid options:
  2985. SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED
  2986. (default 'SUCCESS')
  2987. :arg list groovy-script: Paths to Groovy scripts
  2988. :groovy-script: * **file-path** (`str`) - Path to Groovy scripts
  2989. * **role** (`str`) - Execute scripts on. One of
  2990. MASTER / SLAVE / BOTH. (default 'BOTH')
  2991. * **build-on** (`list`) - Build statuses which trigger
  2992. the scripts. Valid options:
  2993. SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED
  2994. (default 'SUCCESS')
  2995. :arg list groovy: Inline Groovy
  2996. :groovy: * **content** (`str`) - Inline Groovy script.
  2997. * **role** (`str`) - Execute scripts on. One of
  2998. MASTER / SLAVE / BOTH. (default 'BOTH')
  2999. * **build-on** (`list`) - Build statuses which trigger
  3000. the scripts. Valid options:
  3001. SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED
  3002. (default 'SUCCESS')
  3003. :arg list builders: Execute any number of supported Jenkins builders.
  3004. :builders: * **build-steps** (`str`) - Any supported builders,
  3005. see :doc:`builders`.
  3006. * **role** (`str`) - Execute scripts on. One of
  3007. MASTER / SLAVE / BOTH. (default 'BOTH')
  3008. * **build-on** (`list`) - Build statuses which trigger
  3009. the scripts. Valid options:
  3010. SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED
  3011. (default 'SUCCESS')
  3012. :arg bool mark-unstable-if-failed: Build will be marked unstable
  3013. if job will be successfully completed but publishing script will return
  3014. non zero exit code (default false)
  3015. Deprecated Options for versions < 2.0 of plugin:
  3016. :arg bool onsuccess: Deprecated, replaced with script-only-if-succeeded
  3017. :arg bool script-only-if-succeeded: Scripts and builders are run only if
  3018. the build succeeded (default true)
  3019. :arg bool onfailure: Deprecated, replaced with script-only-if-failed
  3020. :arg bool script-only-if-failed: Scripts and builders are run only if the
  3021. build failed (default false)
  3022. :arg str execute-on: For matrix projects, scripts can be run after each
  3023. axis is built (`axes`), after all axis of the matrix are built
  3024. (`matrix`) or after each axis AND the matrix are built (`both`).
  3025. The `script-only-if-succeeded` and `bool script-only-if-failed` options are
  3026. confusing. If you want the post build to always run regardless of the build
  3027. status, you should set them both to `false`.
  3028. Minimal Example:
  3029. .. literalinclude::
  3030. /../../tests/publishers/fixtures/postbuildscript-minimal.yaml
  3031. :language: yaml
  3032. Full Example:
  3033. .. literalinclude::
  3034. /../../tests/publishers/fixtures/postbuildscript-full.yaml
  3035. :language: yaml
  3036. Example(s) versions < 2.0:
  3037. .. literalinclude::
  3038. /../../tests/publishers/fixtures/postbuildscript001.yaml
  3039. :language: yaml
  3040. You can also execute :doc:`builders </builders>`:
  3041. .. literalinclude::
  3042. /../../tests/publishers/fixtures/postbuildscript002.yaml
  3043. :language: yaml
  3044. Run once after the whole matrix (all axes) is built:
  3045. .. literalinclude::
  3046. /../../tests/publishers/fixtures/postbuildscript003.yaml
  3047. :language: yaml
  3048. """
  3049. pbs_xml = XML.SubElement(
  3050. xml_parent,
  3051. 'org.jenkinsci.plugins.postbuildscript.PostBuildScript')
  3052. info = registry.get_plugin_info('postbuildscript')
  3053. # Note: Assume latest version of plugin is preferred config format
  3054. version = pkg_resources.parse_version(
  3055. info.get('version', str(sys.maxsize)))
  3056. if version >= pkg_resources.parse_version('2.0'):
  3057. pbs_xml = XML.SubElement(pbs_xml, 'config')
  3058. mapping = [
  3059. ('mark-unstable-if-failed', 'markBuildUnstable', False),
  3060. ]
  3061. helpers.convert_mapping_to_xml(pbs_xml, data, mapping, fail_required=True)
  3062. if version >= pkg_resources.parse_version("2.0"):
  3063. ################
  3064. # Script Files #
  3065. ################
  3066. script_mapping = [
  3067. ('role', 'role', 'BOTH'),
  3068. ('file-path', 'filePath', False),
  3069. ]
  3070. sf_path = 'org.jenkinsci.plugins.postbuildscript.model.ScriptFile'
  3071. sf_xml = XML.SubElement(pbs_xml, 'scriptFiles')
  3072. for gs_data in data.get('generic-script', []):
  3073. x = XML.SubElement(sf_xml, sf_path)
  3074. results_xml = XML.SubElement(x, 'results')
  3075. for result in gs_data.get('build-on', ['SUCCESS']):
  3076. XML.SubElement(results_xml, 'string').text = result
  3077. helpers.convert_mapping_to_xml(
  3078. x, gs_data, script_mapping, fail_required=True)
  3079. XML.SubElement(x, 'scriptType').text = 'GENERIC'
  3080. for gs_data in data.get('groovy-script', []):
  3081. x = XML.SubElement(sf_xml, sf_path)
  3082. results_xml = XML.SubElement(x, 'results')
  3083. for result in gs_data.get('build-on', ['SUCCESS']):
  3084. XML.SubElement(results_xml, 'string').text = result
  3085. helpers.convert_mapping_to_xml(
  3086. x, gs_data, script_mapping, fail_required=True)
  3087. XML.SubElement(x, 'scriptType').text = 'GROOVY'
  3088. #################
  3089. # Inline Groovy #
  3090. #################
  3091. groovy_mapping = [
  3092. ('role', 'role', 'BOTH'),
  3093. ('content', 'content', False),
  3094. ]
  3095. gs_path = 'org.jenkinsci.plugins.postbuildscript.model.Script'
  3096. gs_xml = XML.SubElement(pbs_xml, 'groovyScripts')
  3097. for gs_data in data.get('groovy', []):
  3098. x = XML.SubElement(gs_xml, gs_path)
  3099. results_xml = XML.SubElement(x, 'results')
  3100. for result in gs_data.get('build-on', ['SUCCESS']):
  3101. XML.SubElement(results_xml, 'string').text = result
  3102. helpers.convert_mapping_to_xml(
  3103. x, gs_data, groovy_mapping, fail_required=True)
  3104. ############
  3105. # Builders #
  3106. ############
  3107. builder_mapping = [
  3108. ('role', 'role', 'BOTH'),
  3109. ]
  3110. bs_path = 'org.jenkinsci.plugins.postbuildscript.model.PostBuildStep'
  3111. bs_xml = XML.SubElement(pbs_xml, 'buildSteps')
  3112. for bs_data in data.get('builders', []):
  3113. x = XML.SubElement(bs_xml, bs_path)
  3114. results_xml = XML.SubElement(x, 'results')
  3115. for result in bs_data.get('build-on', ['SUCCESS']):
  3116. XML.SubElement(results_xml, 'string').text = result
  3117. helpers.convert_mapping_to_xml(
  3118. x, bs_data, builder_mapping, fail_required=True)
  3119. build_steps_xml = XML.SubElement(x, 'buildSteps')
  3120. for builder in bs_data.get('build-steps'):
  3121. registry.dispatch('builder', build_steps_xml, builder)
  3122. else: # Options below are all deprecated in version < 2.0 of plugin
  3123. # Shell/Groovy in a file
  3124. script_types = {
  3125. 'generic-script': 'GenericScript',
  3126. 'groovy-script': 'GroovyScriptFile',
  3127. }
  3128. # Assuming yaml preserves order of input data make sure
  3129. # corresponding XML steps are generated in the same order
  3130. build_scripts = [(k, v) for k, v in data.items()
  3131. if k in script_types or k in ['groovy', 'builders']]
  3132. for step, script_data in build_scripts:
  3133. if step in script_types:
  3134. scripts_xml = XML.SubElement(
  3135. pbs_xml, step[:-len('-script')] + 'ScriptFileList')
  3136. for shell_script in script_data:
  3137. script_xml = XML.SubElement(
  3138. scripts_xml,
  3139. 'org.jenkinsci.plugins.postbuildscript.'
  3140. + script_types[step])
  3141. file_path_xml = XML.SubElement(script_xml, 'filePath')
  3142. file_path_xml.text = shell_script
  3143. # Inlined Groovy
  3144. if step == 'groovy':
  3145. groovy_inline_xml = XML.SubElement(
  3146. pbs_xml, 'groovyScriptContentList')
  3147. for groovy in script_data:
  3148. groovy_xml = XML.SubElement(
  3149. groovy_inline_xml,
  3150. 'org.jenkinsci.plugins.postbuildscript.'
  3151. 'GroovyScriptContent'
  3152. )
  3153. groovy_content = XML.SubElement(groovy_xml, 'content')
  3154. groovy_content.text = groovy
  3155. # Inject builders
  3156. if step == 'builders':
  3157. build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps')
  3158. for builder in script_data:
  3159. registry.dispatch('builder', build_steps_xml, builder)
  3160. # When to run the build? Note the plugin let one specify both options
  3161. # although they are antinomic
  3162. # onsuccess and onfailure parameters are deprecated, this is to keep
  3163. # backwards compatability
  3164. success_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfSuccess')
  3165. if 'script-only-if-succeeded' in data:
  3166. success_xml.text = str(
  3167. data.get('script-only-if-succeeded', True)).lower()
  3168. else:
  3169. success_xml.text = str(data.get('onsuccess', True)).lower()
  3170. failure_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfFailure')
  3171. if 'script-only-if-failed' in data:
  3172. failure_xml.text = str(
  3173. data.get('script-only-if-failed', False)).lower()
  3174. else:
  3175. failure_xml.text = str(data.get('onfailure', False)).lower()
  3176. # TODO: we may want to avoid setting "execute-on" on non-matrix jobs,
  3177. # either by skipping this part or by raising an error to let the user
  3178. # know an attempt was made to set execute-on on a non-matrix job.
  3179. # There are currently no easy ways to check for this though.
  3180. if 'execute-on' in data:
  3181. valid_values = ('matrix', 'axes', 'both')
  3182. execute_on = data['execute-on'].lower()
  3183. if execute_on not in valid_values:
  3184. raise JenkinsJobsException(
  3185. 'execute-on must be one of %s, got %s' %
  3186. valid_values, execute_on
  3187. )
  3188. execute_on_xml = XML.SubElement(pbs_xml, 'executeOn')
  3189. execute_on_xml.text = execute_on.upper()
  3190. def xml_summary(registry, xml_parent, data):
  3191. """yaml: xml-summary
  3192. Adds support for the Summary Display Plugin
  3193. Requires the Jenkins :jenkins-wiki:`Summary Display Plugin
  3194. <Summary+Display+Plugin>`.
  3195. :arg str files: Files to parse (required)
  3196. :arg bool shown-on-project-page: Display summary on project page
  3197. (default false)
  3198. Minimal Example:
  3199. .. literalinclude::
  3200. /../../tests/publishers/fixtures/xml-summary-minimal.yaml
  3201. :language: yaml
  3202. Full Example:
  3203. .. literalinclude:: /../../tests/publishers/fixtures/xml-summary-full.yaml
  3204. :language: yaml
  3205. """
  3206. summary = XML.SubElement(
  3207. xml_parent, 'hudson.plugins.summary__report.ACIPluginPublisher')
  3208. summary.set('plugin', 'summary_report')
  3209. mapping = [
  3210. ('files', 'name', None),
  3211. ('shown-on-project-page', 'shownOnProjectPage', False),
  3212. ]
  3213. helpers.convert_mapping_to_xml(summary, data, mapping, fail_required=True)
  3214. def robot(registry, xml_parent, data):
  3215. """yaml: robot
  3216. Adds support for the Robot Framework Plugin
  3217. Requires the Jenkins :jenkins-wiki:`Robot Framework Plugin
  3218. <Robot+Framework+Plugin>`.
  3219. :arg str output-path: Path to directory containing robot xml and html files
  3220. relative to build workspace. (required)
  3221. :arg str log-file-link: Name of log or report file to be linked on jobs
  3222. front page (default '')
  3223. :arg str report-html: Name of the html file containing robot test report
  3224. (default 'report.html')
  3225. :arg str log-html: Name of the html file containing detailed robot test log
  3226. (default 'log.html')
  3227. :arg str output-xml: Name of the xml file containing robot output
  3228. (default 'output.xml')
  3229. :arg str pass-threshold: Minimum percentage of passed tests to consider
  3230. the build successful (default 0.0)
  3231. :arg str unstable-threshold: Minimum percentage of passed test to
  3232. consider the build as not failed (default 0.0)
  3233. :arg bool only-critical: Take only critical tests into account when
  3234. checking the thresholds (default true)
  3235. :arg list other-files: list other files to archive (default '')
  3236. :arg bool archive-output-xml: Archive output xml file to server
  3237. (default true)
  3238. :arg bool enable-cache: Enable cache for test results (default true)
  3239. Minimal Example:
  3240. .. literalinclude:: /../../tests/publishers/fixtures/robot-minimal.yaml
  3241. :language: yaml
  3242. Full Example:
  3243. .. literalinclude:: /../../tests/publishers/fixtures/robot-full.yaml
  3244. :language: yaml
  3245. """
  3246. parent = XML.SubElement(xml_parent, 'hudson.plugins.robot.RobotPublisher')
  3247. parent.set('plugin', 'robot')
  3248. mappings = [
  3249. ('output-path', 'outputPath', None),
  3250. ('log-file-link', 'logFileLink', ''),
  3251. ('report-html', 'reportFileName', 'report.html'),
  3252. ('log-html', 'logFileName', 'log.html'),
  3253. ('output-xml', 'outputFileName', 'output.xml'),
  3254. ('pass-threshold', 'passThreshold', '0.0'),
  3255. ('unstable-threshold', 'unstableThreshold', '0.0'),
  3256. ('only-critical', 'onlyCritical', True),
  3257. ('enable-cache', 'enableCache', True)
  3258. ]
  3259. helpers.convert_mapping_to_xml(parent, data, mappings, fail_required=True)
  3260. other_files = XML.SubElement(parent, 'otherFiles')
  3261. for other_file in data.get('other-files', []):
  3262. XML.SubElement(other_files, 'string').text = str(other_file)
  3263. XML.SubElement(parent, 'disableArchiveOutput').text = str(
  3264. not data.get('archive-output-xml', True)).lower()
  3265. def warnings(registry, xml_parent, data):
  3266. """yaml: warnings
  3267. Generate trend report for compiler warnings in the console log or
  3268. in log files. Requires the Jenkins :jenkins-wiki:`Warnings Plugin
  3269. <Warnings+Plugin>`.
  3270. :arg list console-log-parsers: The parser to use to scan the console
  3271. log (default '')
  3272. :arg dict workspace-file-scanners:
  3273. :workspace-file-scanners:
  3274. * **file-pattern** (`str`) -- Fileset 'includes' setting that
  3275. specifies the files to scan for warnings (required)
  3276. * **scanner** (`str`) -- The parser to use to scan the files
  3277. provided in workspace-file-pattern (default '')
  3278. :arg str files-to-include: Comma separated list of regular
  3279. expressions that specifies the files to include in the report
  3280. (based on their absolute filename). By default all files are
  3281. included
  3282. :arg str files-to-ignore: Comma separated list of regular expressions
  3283. that specifies the files to exclude from the report (based on their
  3284. absolute filename). (default '')
  3285. :arg str messages-to-ignore: Newline separated list of regular
  3286. expressions that specifies the warning messages to exclude form the
  3287. report (based on the warning messages). By default all warning
  3288. messages are included
  3289. :arg str categories-to-ignore: Newline separated list of regular
  3290. expressions that specifies the warning messages to exclude form the
  3291. report (based on the warning categories). By default all warning
  3292. categories are included
  3293. :arg bool run-always: By default, this plug-in runs only for stable or
  3294. unstable builds, but not for failed builds. Set to true if the
  3295. plug-in should run even for failed builds. (default false)
  3296. :arg bool detect-modules: Determines if Ant or Maven modules should be
  3297. detected for all files that contain warnings. Activating this
  3298. option may increase your build time since the detector scans
  3299. the whole workspace for 'build.xml' or 'pom.xml' files in order
  3300. to assign the correct module names. (default false)
  3301. :arg bool resolve-relative-paths: Determines if relative paths in
  3302. warnings should be resolved using a time expensive operation that
  3303. scans the whole workspace for matching files. Deactivate this
  3304. option if you encounter performance problems. (default false)
  3305. :arg int health-threshold-high: The upper threshold for the build
  3306. health. If left empty then no health report is created. If
  3307. the actual number of warnings is between the provided
  3308. thresholds then the build health is interpolated (default '')
  3309. :arg int health-threshold-low: The lower threshold for the build
  3310. health. See health-threshold-high. (default '')
  3311. :arg dict health-priorities: Determines which warning priorities
  3312. should be considered when evaluating the build health (default
  3313. all-priorities)
  3314. :health-priorities values:
  3315. * **priority-high** -- Only priority high
  3316. * **high-and-normal** -- Priorities high and normal
  3317. * **all-priorities** -- All priorities
  3318. :arg dict total-thresholds: If the number of total warnings is greater
  3319. than one of these thresholds then a build is considered as unstable
  3320. or failed, respectively. (default '')
  3321. :total-thresholds:
  3322. * **unstable** (`dict`)
  3323. :unstable: * **total-all** (`int`)
  3324. * **total-high** (`int`)
  3325. * **total-normal** (`int`)
  3326. * **total-low** (`int`)
  3327. * **failed** (`dict`)
  3328. :failed: * **total-all** (`int`)
  3329. * **total-high** (`int`)
  3330. * **total-normal** (`int`)
  3331. * **total-low** (`int`)
  3332. :arg dict new-thresholds: If the specified number of new warnings exceeds
  3333. one of these thresholds then a build is considered as unstable or
  3334. failed, respectively. (default '')
  3335. :new-thresholds:
  3336. * **unstable** (`dict`)
  3337. :unstable: * **new-all** (`int`)
  3338. * **new-high** (`int`)
  3339. * **new-normal** (`int`)
  3340. * **new-low** (`int`)
  3341. * **failed** (`dict`)
  3342. :failed: * **new-all** (`int`)
  3343. * **new-high** (`int`)
  3344. * **new-normal** (`int`)
  3345. * **new-high** (`int`)
  3346. :arg bool use-delta-for-new-warnings: If set then the number of new
  3347. warnings is calculated by subtracting the total number of warnings
  3348. of the current build from the reference build. This may lead to wrong
  3349. results if you have both fixed and new warnings in a build. If not set,
  3350. then the number of new warnings is calculated by an asymmetric set
  3351. difference of the warnings in the current and reference build. This
  3352. will find all new warnings even if the number of total warnings is
  3353. decreasing. However, sometimes false positives will be reported due
  3354. to minor changes in a warning (refactoring of variable of method
  3355. names, etc.) (default false)
  3356. :arg bool use-previous-build-as-reference: If set the number of new
  3357. warnings will always be computed based on the previous build, even if
  3358. that build is unstable (due to a violated warning threshold).
  3359. Otherwise the last build that did not violate any given threshold will
  3360. be used as
  3361. reference. It is recommended to uncheck this option if the plug-in
  3362. should ensure that all new warnings will be finally fixed in subsequent
  3363. builds. (default false)
  3364. :arg bool only-use-stable-builds-as-reference: The number of new warnings
  3365. will be calculated based on the last stable build, allowing reverts
  3366. of unstable builds where the number of warnings was decreased.
  3367. (default false)
  3368. :arg str default-encoding: Default encoding when parsing or showing files
  3369. Leave empty to use default encoding of platform (default '')
  3370. Minimal Example:
  3371. .. literalinclude:: /../../tests/publishers/fixtures/warnings-minimal.yaml
  3372. :language: yaml
  3373. Full Example:
  3374. .. literalinclude:: /../../tests/publishers/fixtures/warnings-full.yaml
  3375. :language: yaml
  3376. """
  3377. warnings = XML.SubElement(xml_parent,
  3378. 'hudson.plugins.warnings.'
  3379. 'WarningsPublisher')
  3380. warnings.set('plugin', 'warnings')
  3381. console = XML.SubElement(warnings, 'consoleParsers')
  3382. for parser in data.get('console-log-parsers', []):
  3383. console_parser = XML.SubElement(console,
  3384. 'hudson.plugins.warnings.'
  3385. 'ConsoleParser')
  3386. XML.SubElement(console_parser, 'parserName').text = parser
  3387. workspace = XML.SubElement(warnings, 'parserConfigurations')
  3388. for wfs in data.get('workspace-file-scanners', []):
  3389. workspace_pattern = XML.SubElement(workspace,
  3390. 'hudson.plugins.warnings.'
  3391. 'ParserConfiguration')
  3392. workspace_pattern_mappings = [
  3393. ('file-pattern', 'pattern', None),
  3394. ('scanner', 'parserName', '')
  3395. ]
  3396. helpers.convert_mapping_to_xml(workspace_pattern,
  3397. wfs,
  3398. workspace_pattern_mappings,
  3399. fail_required=True)
  3400. prioritiesDict = {'priority-high': 'high',
  3401. 'high-and-normal': 'normal',
  3402. 'all-priorities': 'low'}
  3403. warnings_mappings = [
  3404. ('files-to-include', 'includePattern', ''),
  3405. ('files-to-ignore', 'excludePattern', ''),
  3406. ('messages-to-ignore', 'messagesPattern', ''),
  3407. ('categories-to-ignore', 'categoriesPattern', ''),
  3408. ('plugin-name', 'pluginName', '[WARNINGS]'),
  3409. ('run-always', 'canRunOnFailed', False),
  3410. ('detect-modules', 'shouldDetectModules', False),
  3411. ('health-threshold-high', 'healthy', ''),
  3412. ('health-threshold-low', 'unHealthy', ''),
  3413. ('health-priorities',
  3414. 'thresholdLimit',
  3415. 'all-priorities',
  3416. prioritiesDict),
  3417. ('default-encoding', 'defaultEncoding', '')
  3418. ]
  3419. helpers.convert_mapping_to_xml(
  3420. warnings, data, warnings_mappings, fail_required=True)
  3421. # Note the logic reversal (included here to match the GUI)
  3422. XML.SubElement(warnings, 'doNotResolveRelativePaths').text = str(
  3423. not data.get('resolve-relative-paths', False)).lower()
  3424. td = XML.SubElement(warnings, 'thresholds')
  3425. for base in ["total", "new"]:
  3426. thresholds = data.get("%s-thresholds" % base, {})
  3427. for status in ["unstable", "failed"]:
  3428. bystatus = thresholds.get(status, {})
  3429. for level in ["all", "high", "normal", "low"]:
  3430. val = str(bystatus.get("%s-%s" % (base, level), ''))
  3431. XML.SubElement(td, "%s%s%s" % (status,
  3432. base.capitalize(), level.capitalize())
  3433. ).text = val
  3434. if data.get('new-thresholds'):
  3435. XML.SubElement(warnings, 'dontComputeNew').text = 'false'
  3436. delta = data.get('use-delta-for-new-warnings', False)
  3437. XML.SubElement(warnings, 'useDeltaValues').text = str(delta).lower()
  3438. use_previous_build = data.get('use-previous-build-as-reference', False)
  3439. XML.SubElement(warnings, 'usePreviousBuildAsReference').text = str(
  3440. use_previous_build).lower()
  3441. use_stable_builds = data.get('only-use-stable-builds-as-reference',
  3442. False)
  3443. XML.SubElement(warnings, 'useStableBuildAsReference').text = str(
  3444. use_stable_builds).lower()
  3445. else:
  3446. XML.SubElement(warnings, 'dontComputeNew').text = 'true'
  3447. XML.SubElement(warnings, 'useDeltaValues').text = 'false'
  3448. XML.SubElement(warnings, 'usePreviousBuildAsReference').text = 'false'
  3449. XML.SubElement(warnings, 'useStableBuildAsReference').text = 'false'
  3450. def sloccount(registry, xml_parent, data):
  3451. """yaml: sloccount
  3452. Generates the trend report for SLOCCount
  3453. Requires the Jenkins :jenkins-wiki:`SLOCCount Plugin <SLOCCount+Plugin>`.
  3454. :arg str report-files: Setting that specifies the generated raw
  3455. SLOCCount report files. Be sure not to include any non-report files
  3456. into this pattern. The report files must have been generated by
  3457. sloccount using the "--wide --details" options.
  3458. (default '\*\*/sloccount.sc')
  3459. :arg str charset: The character encoding to be used to read the SLOCCount
  3460. result files. (default 'UTF-8')
  3461. :arg int builds-in-graph: Maximal number of last successful builds, that
  3462. are displayed in the trend graphs. (default 0)
  3463. :arg bool comment-is-code: This option is considered only in the cloc
  3464. report parser and is ignored in the SLOCCount one. (default false)
  3465. :arg bool ignore-build-failure: Try to process the report files even if
  3466. the build is not successful. (default false)
  3467. Minimal Example:
  3468. .. literalinclude:: /../../tests/publishers/fixtures/sloccount-minimal.yaml
  3469. :language: yaml
  3470. Full Example:
  3471. .. literalinclude::
  3472. /../../tests/publishers/fixtures/sloccount-full.yaml
  3473. :language: yaml
  3474. """
  3475. top = XML.SubElement(xml_parent,
  3476. 'hudson.plugins.sloccount.SloccountPublisher')
  3477. top.set('plugin', 'sloccount')
  3478. mappings = [
  3479. ('report-files', 'pattern', '**/sloccount.sc'),
  3480. ('charset', 'encoding', 'UTF-8'),
  3481. ('builds-in-graph', 'numBuildsInGraph', 0),
  3482. ('comment-is-code', 'commentIsCode', False),
  3483. ('ignore-build-failure', 'ignoreBuildFailure', False)
  3484. ]
  3485. helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
  3486. def ircbot(registry, xml_parent, data):
  3487. """yaml: ircbot
  3488. ircbot enables Jenkins to send build notifications via IRC and lets you
  3489. interact with Jenkins via an IRC bot.
  3490. Requires the Jenkins :jenkins-wiki:`IRC Plugin <IRC+Plugin>`.
  3491. :arg string strategy: When to send notifications
  3492. :strategy values:
  3493. * **all** always (default)
  3494. * **any-failure** on any failure
  3495. * **failure-and-fixed** on failure and fixes
  3496. * **new-failure-and-fixed** on new failure and fixes
  3497. * **statechange-only** only on state change
  3498. :arg bool notify-start: Whether to send notifications to channels when a
  3499. build starts (default false)
  3500. :arg bool notify-committers: Whether to send notifications to the users
  3501. that are suspected of having broken this build (default false)
  3502. :arg bool notify-culprits: Also send notifications to 'culprits' from
  3503. previous unstable/failed builds (default false)
  3504. :arg bool notify-upstream: Whether to send notifications to upstream
  3505. committers if no committers were found for a broken build
  3506. (default false)
  3507. :arg bool notify-fixers: Whether to send notifications to the users that
  3508. have fixed a broken build (default false)
  3509. :arg string message-type: Channel Notification Message.
  3510. :message-type values:
  3511. * **summary-scm** for summary and SCM changes (default)
  3512. * **summary** for summary only
  3513. * **summary-params** for summary and build parameters
  3514. * **summary-scm-fail** for summary, SCM changes, failures)
  3515. :arg list channels: list channels definitions
  3516. If empty, it takes channel from Jenkins configuration.
  3517. (default empty)
  3518. WARNING: the IRC plugin requires the channel to be configured in the
  3519. system wide configuration or the jobs will fail to emit notifications
  3520. to the channel
  3521. :Channel: * **name** (`str`) Channel name
  3522. * **password** (`str`) Channel password (optional)
  3523. * **notify-only** (`bool`) Set to true if you want to
  3524. disallow bot commands (default false)
  3525. :arg string matrix-notifier: notify for matrix projects
  3526. instant-messaging-plugin injects an additional
  3527. field in the configuration form whenever the
  3528. project is a multi-configuration project
  3529. :matrix-notifier values:
  3530. * **all**
  3531. * **only-configurations** (default)
  3532. * **only-parent**
  3533. Minimal Example:
  3534. .. literalinclude:: /../../tests/publishers/fixtures/ircbot-minimal.yaml
  3535. :language: yaml
  3536. Full Example:
  3537. .. literalinclude:: /../../tests/publishers/fixtures/ircbot-full.yaml
  3538. :language: yaml
  3539. """
  3540. top = XML.SubElement(xml_parent, 'hudson.plugins.ircbot.IrcPublisher')
  3541. top.set('plugin', 'ircbot')
  3542. message_dict = {'summary-scm': 'DefaultBuildToChatNotifier',
  3543. 'summary': 'SummaryOnlyBuildToChatNotifier',
  3544. 'summary-params': 'BuildParametersBuildToChatNotifier',
  3545. 'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
  3546. message = data.get('message-type', 'summary-scm')
  3547. if message not in message_dict:
  3548. raise JenkinsJobsException("message-type entered is not valid, must "
  3549. "be one of: %s" %
  3550. ", ".join(message_dict.keys()))
  3551. message = "hudson.plugins.im.build_notify." + message_dict.get(message)
  3552. XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
  3553. targets = XML.SubElement(top, 'targets')
  3554. channels = data.get('channels', [])
  3555. for channel in channels:
  3556. sub = XML.SubElement(targets,
  3557. 'hudson.plugins.im.GroupChatIMMessageTarget')
  3558. sub_mappings = [
  3559. ('name', 'name', ''),
  3560. ('password', 'password', ''),
  3561. ('notify-only', 'notificationOnly', False)
  3562. ]
  3563. helpers.convert_mapping_to_xml(
  3564. sub, channel, sub_mappings, fail_required=True)
  3565. strategy_dict = {'all': 'ALL',
  3566. 'any-failure': 'ANY_FAILURE',
  3567. 'failure-and-fixed': 'FAILURE_AND_FIXED',
  3568. 'new-failure-and-fixed': 'NEW_FAILURE_AND_FIXED',
  3569. 'statechange-only': 'STATECHANGE_ONLY'}
  3570. matrix_dict = {'all': 'ALL',
  3571. 'only-configurations': 'ONLY_CONFIGURATIONS',
  3572. 'only-parent': 'ONLY_PARENT'}
  3573. mappings = [
  3574. ('strategy', 'strategy', 'all', strategy_dict),
  3575. ('notify-start', 'notifyOnBuildStart', False),
  3576. ('notify-committers', 'notifySuspects', False),
  3577. ('notify-culprits', 'notifyCulprits', False),
  3578. ('notify-fixers', 'notifyFixers', False),
  3579. ('notify-upstream', 'notifyUpstreamCommitters', False),
  3580. ('matrix-notifier',
  3581. 'matrixMultiplier',
  3582. 'only-configurations',
  3583. matrix_dict)
  3584. ]
  3585. helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
  3586. def plot(registry, xml_parent, data):
  3587. """yaml: plot
  3588. Plot provides generic plotting (or graphing).
  3589. Requires the Jenkins :jenkins-wiki:`Plot Plugin <Plot+Plugin>`.
  3590. :arg str title: title for the graph (default '')
  3591. :arg str yaxis: title of Y axis (default '')
  3592. :arg int width: the width of the plot in pixels (default 750)
  3593. :arg int height: the height of the plot in pixels (default 450)
  3594. :arg str group: name of the group to which the plot belongs (required)
  3595. :arg int num-builds: number of builds to plot across
  3596. (default plot all builds)
  3597. :arg str style: Specifies the graph style of the plot
  3598. Can be: area, bar, bar3d, line, line3d, stackedArea, stackedbar,
  3599. stackedbar3d, waterfall (default 'line')
  3600. :arg bool use-description: When false, the X-axis labels are formed using
  3601. build numbers and dates, and the corresponding tooltips contain the
  3602. build descriptions. When enabled, the contents of the labels and
  3603. tooltips are swapped, with the descriptions used as X-axis labels and
  3604. the build number and date used for tooltips. (default false)
  3605. :arg bool exclude-zero-yaxis: When false, Y-axis contains the value zero
  3606. even if it is not included in the data series. When true, the value
  3607. zero is not automatically included. (default false)
  3608. :arg bool logarithmic-yaxis: When true, the Y-axis will use a logarithmic
  3609. scale. By default, the Y-axis uses a linear scale. (default false)
  3610. :arg bool keep-records: When true, show all builds up to 'Number of
  3611. builds to include'. (default false)
  3612. :arg str csv-file-name: Use for choosing the file name in which the data
  3613. will be persisted. If none specified and random name is generated as
  3614. done in the Jenkins Plot plugin. (default random generated .csv
  3615. filename, same behaviour as the Jenkins Plot plugin)
  3616. :arg list series: list data series definitions
  3617. :Series: * **file** (`str`) : files to include
  3618. * **inclusion-flag** filtering mode for CSV files. Possible
  3619. values are:
  3620. * **off** (default)
  3621. * **include-by-string**
  3622. * **exclude-by-string**
  3623. * **include-by-column**
  3624. * **exclude-by-column**
  3625. * **exclude** (`str`) : exclude pattern for CSV file.
  3626. * **url** (`str`) : for 'csv' and 'xml' file types
  3627. used when you click on a point (default empty)
  3628. * **display-table** (`bool`) : for 'csv' file type
  3629. if true, original CSV will be shown above plot (default false)
  3630. * **label** (`str`) : used by 'properties' file type
  3631. Specifies the legend label for this data series.
  3632. (default empty)
  3633. * **format** (`str`) : Type of file where we get datas.
  3634. Can be: properties, csv, xml
  3635. * **xpath-type** (`str`) : The result type of the expression must
  3636. be supplied due to limitations in the java.xml.xpath parsing.
  3637. The result can be: node, nodeset, boolean, string, or number.
  3638. Strings and numbers will be converted to double. Boolean will
  3639. be converted to 1 for true, and 0 for false. (default 'node')
  3640. * **xpath** (`str`) : used by 'xml' file type
  3641. Xpath which selects the values that should be plotted.
  3642. Minimal Example:
  3643. .. literalinclude:: /../../tests/publishers/fixtures/plot-minimal.yaml
  3644. :language: yaml
  3645. Full Example:
  3646. .. literalinclude:: /../../tests/publishers/fixtures/plot-full.yaml
  3647. :language: yaml
  3648. """
  3649. top = XML.SubElement(xml_parent, 'hudson.plugins.plot.PlotPublisher')
  3650. plots = XML.SubElement(top, 'plots')
  3651. format_dict = {'properties': 'hudson.plugins.plot.PropertiesSeries',
  3652. 'csv': 'hudson.plugins.plot.CSVSeries',
  3653. 'xml': 'hudson.plugins.plot.XMLSeries'}
  3654. xpath_dict = {'nodeset': 'NODESET', 'node': 'NODE', 'string': 'STRING',
  3655. 'boolean': 'BOOLEAN', 'number': 'NUMBER'}
  3656. inclusion_dict = {'off': 'OFF',
  3657. 'include-by-string': 'INCLUDE_BY_STRING',
  3658. 'exclude-by-string': 'EXCLUDE_BY_STRING',
  3659. 'include-by-column': 'INCLUDE_BY_COLUMN',
  3660. 'exclude-by-column': 'EXCLUDE_BY_COLUMN'}
  3661. style_list = ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea',
  3662. 'stackedbar', 'stackedbar3d', 'waterfall']
  3663. plot_mappings = [
  3664. ('title', 'title', ''),
  3665. ('yaxis', 'yaxis', ''),
  3666. ('width', 'width', '750'),
  3667. ('height', 'height', '450'),
  3668. ('csv-file-name', 'csvFileName', ''),
  3669. ('group', 'group', None),
  3670. ('use-description', 'useDescr', False),
  3671. ('exclude-zero-yaxis', 'exclZero', False),
  3672. ('logarithmic-yaxis', 'logarithmic', False),
  3673. ('keep-records', 'keepRecords', False),
  3674. ('num-builds', 'numBuilds', ''),
  3675. ('style', 'style', 'line', style_list),
  3676. ]
  3677. plot_csv_mappings = [
  3678. ('inclusion-flag', 'inclusionFlag', 'off', inclusion_dict),
  3679. ('exclude', 'exclusionValues', ''),
  3680. ('url', 'url', ''),
  3681. ('display-table', 'displayTableFlag', False)
  3682. ]
  3683. plot_xml_mappings = [
  3684. ('url', 'url', ''),
  3685. ('xpath', 'xpathString', ''),
  3686. ('xpath-type', 'nodeTypeString', 'node', xpath_dict)
  3687. ]
  3688. for plot in data:
  3689. plugin = XML.SubElement(plots, 'hudson.plugins.plot.Plot')
  3690. helpers.convert_mapping_to_xml(
  3691. plugin, plot, plot_mappings, fail_required=True)
  3692. topseries = XML.SubElement(plugin, 'series')
  3693. series = plot['series']
  3694. for serie in series:
  3695. format_data = serie.get('format')
  3696. if format_data not in format_dict:
  3697. raise JenkinsJobsException("format entered is not valid, must "
  3698. "be one of: %s" %
  3699. " , ".join(format_dict.keys()))
  3700. subserie = XML.SubElement(topseries, format_dict.get(format_data))
  3701. XML.SubElement(subserie, 'file').text = serie.get('file')
  3702. if format_data == 'properties':
  3703. XML.SubElement(subserie, 'label').text = serie.get('label', '')
  3704. if format_data == 'csv':
  3705. helpers.convert_mapping_to_xml(
  3706. subserie, serie, plot_csv_mappings, fail_required=True)
  3707. if serie.get('exclude', ''):
  3708. exclude_strings = serie.get('exclude', '').split(',')
  3709. exclusionset = XML.SubElement(subserie, 'strExclusionSet')
  3710. for exclude_string in exclude_strings:
  3711. XML.SubElement(exclusionset, 'string').text = \
  3712. exclude_string
  3713. if format_data == 'xml':
  3714. helpers.convert_mapping_to_xml(
  3715. subserie, serie, plot_xml_mappings, fail_required=True)
  3716. XML.SubElement(subserie, 'fileType').text = serie.get('format')
  3717. def git(registry, xml_parent, data):
  3718. """yaml: git
  3719. This plugin will configure the Jenkins Git plugin to
  3720. push merge results, tags, and/or branches to
  3721. remote repositories after the job completes.
  3722. Requires the Jenkins :jenkins-wiki:`Git Plugin <Git+Plugin>`.
  3723. :arg bool push-merge: push merges back to the origin specified in the
  3724. pre-build merge options (default false)
  3725. :arg bool push-only-if-success: Only push to remotes if the build succeeds
  3726. - otherwise, nothing will be pushed.
  3727. (default true)
  3728. :arg bool force-push: Add force option to git push (default false)
  3729. :arg list tags: tags to push at the completion of the build
  3730. :tag: * **remote** (`str`) remote repo name to push to
  3731. (default 'origin')
  3732. * **name** (`str`) name of tag to push
  3733. * **message** (`str`) message content of the tag
  3734. * **create-tag** (`bool`) whether or not to create the tag
  3735. after the build, if this is False then the tag needs to
  3736. exist locally (default false)
  3737. * **update-tag** (`bool`) whether to overwrite a remote tag
  3738. or not (default false)
  3739. :arg list branches: branches to push at the completion of the build
  3740. :branch: * **remote** (`str`) remote repo name to push to
  3741. (default 'origin')
  3742. * **name** (`str`) name of remote branch to push to
  3743. :arg list notes: notes to push at the completion of the build
  3744. :note: * **remote** (`str`) remote repo name to push to
  3745. (default 'origin')
  3746. * **message** (`str`) content of the note
  3747. * **namespace** (`str`) namespace of the note
  3748. (default master)
  3749. * **replace-note** (`bool`) whether to overwrite a note or not
  3750. (default false)
  3751. Minimal Example:
  3752. .. literalinclude:: /../../tests/publishers/fixtures/git-minimal.yaml
  3753. :language: yaml
  3754. Full Example:
  3755. .. literalinclude:: /../../tests/publishers/fixtures/git-full.yaml
  3756. :language: yaml
  3757. """
  3758. mappings = [('push-merge', 'pushMerge', False),
  3759. ('push-only-if-success', 'pushOnlyIfSuccess', True),
  3760. ('force-push', 'forcePush', False)]
  3761. tag_mappings = [('remote', 'targetRepoName', 'origin'),
  3762. ('name', 'tagName', None),
  3763. ('message', 'tagMessage', ''),
  3764. ('create-tag', 'createTag', False),
  3765. ('update-tag', 'updateTag', False)]
  3766. branch_mappings = [('remote', 'targetRepoName', 'origin'),
  3767. ('name', 'branchName', None)]
  3768. note_mappings = [('remote', 'targetRepoName', 'origin'),
  3769. ('message', 'noteMsg', None),
  3770. ('namespace', 'noteNamespace', 'master'),
  3771. ('replace-note', 'noteReplace', False)]
  3772. top = XML.SubElement(xml_parent, 'hudson.plugins.git.GitPublisher')
  3773. XML.SubElement(top, 'configVersion').text = '2'
  3774. helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
  3775. tags = data.get('tags', [])
  3776. if tags:
  3777. xml_tags = XML.SubElement(top, 'tagsToPush')
  3778. for tag in tags:
  3779. xml_tag = XML.SubElement(
  3780. xml_tags,
  3781. 'hudson.plugins.git.GitPublisher_-TagToPush')
  3782. helpers.convert_mapping_to_xml(
  3783. xml_tag, tag['tag'], tag_mappings, fail_required=True)
  3784. branches = data.get('branches', [])
  3785. if branches:
  3786. xml_branches = XML.SubElement(top, 'branchesToPush')
  3787. for branch in branches:
  3788. xml_branch = XML.SubElement(
  3789. xml_branches,
  3790. 'hudson.plugins.git.GitPublisher_-BranchToPush')
  3791. helpers.convert_mapping_to_xml(xml_branch,
  3792. branch['branch'],
  3793. branch_mappings,
  3794. fail_required=True)
  3795. notes = data.get('notes', [])
  3796. if notes:
  3797. xml_notes = XML.SubElement(top, 'notesToPush')
  3798. for note in notes:
  3799. xml_note = XML.SubElement(
  3800. xml_notes,
  3801. 'hudson.plugins.git.GitPublisher_-NoteToPush')
  3802. helpers.convert_mapping_to_xml(
  3803. xml_note, note['note'], note_mappings, fail_required=True)
  3804. def github_notifier(registry, xml_parent, data):
  3805. """yaml: github-notifier
  3806. Set build status on Github commit.
  3807. Requires the Jenkins :jenkins-wiki:`Github Plugin <GitHub+Plugin>`.
  3808. Example:
  3809. .. literalinclude:: /../../tests/publishers/fixtures/github-notifier.yaml
  3810. :language: yaml
  3811. """
  3812. XML.SubElement(xml_parent,
  3813. 'com.cloudbees.jenkins.GitHubCommitNotifier')
  3814. def gitlab_notifier(registry, xml_parent, data):
  3815. """yaml: gitlab-notifier
  3816. Set build status on GitLab commit.
  3817. Requires the Jenkins :jenkins-wiki:`GitLab Plugin <GitLab+Plugin>`.
  3818. :arg str name: The name of the build in GitLab. With this you can
  3819. distinguish different Jenkins jobs for the same commit in GitLab.
  3820. (default 'jenkins')
  3821. :arg bool mark-unstable-as-success: (default false)
  3822. Minimal Example:
  3823. .. literalinclude::
  3824. /../../tests/publishers/fixtures/gitlab-notifier-minimal.yaml
  3825. :language: yaml
  3826. Full Example:
  3827. .. literalinclude::
  3828. /../../tests/publishers/fixtures/gitlab-notifier-full.yaml
  3829. :language: yaml
  3830. """
  3831. top = XML.SubElement(
  3832. xml_parent,
  3833. 'com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher')
  3834. top.set('plugin', 'gitlab-plugin')
  3835. mappings = [
  3836. ('name', 'name', 'jenkins'),
  3837. ('mark-unstable-as-success', 'markUnstableAsSuccess', False),
  3838. ]
  3839. helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
  3840. def zulip(registry, xml_parent, data):
  3841. """yaml: zulip
  3842. Set build status on zulip.
  3843. Requires the Jenkins :jenkins-wiki:`Humbug Plugin <Humbug+Plugin>`.
  3844. Example:
  3845. .. literalinclude:: /../../tests/publishers/fixtures/zulip.yaml
  3846. :language: yaml
  3847. """
  3848. XML.SubElement(xml_parent,
  3849. 'hudson.plugins.humbug.HumbugNotifier')
  3850. def build_publisher(registry, xml_parent, data):
  3851. """yaml: build-publisher
  3852. This plugin allows records from one Jenkins to be published
  3853. on another Jenkins.
  3854. Requires the Jenkins :jenkins-wiki:`Build Publisher Plugin
  3855. <Build+Publisher+Plugin>`.
  3856. :arg bool publish-unstable-builds: publish unstable builds (default true)
  3857. :arg bool publish-failed-builds: publish failed builds (default true)
  3858. :arg int days-to-keep: days to keep when publishing results (optional)
  3859. :arg int num-to-keep: number of jobs to keep in the published results
  3860. (optional)
  3861. Minimal Example:
  3862. .. literalinclude::
  3863. /../../tests/publishers/fixtures/build-publisher-minimal.yaml
  3864. :language: yaml
  3865. Full Example:
  3866. .. literalinclude::
  3867. /../../tests/publishers/fixtures/build-publisher-full.yaml
  3868. :language: yaml
  3869. """
  3870. reporter = XML.SubElement(
  3871. xml_parent,
  3872. 'hudson.plugins.build__publisher.BuildPublisher')
  3873. mappings = [
  3874. ('publish-unstable-builds', 'publishUnstableBuilds', True),
  3875. ('publish-failed-builds', 'publishFailedBuilds', True)
  3876. ]
  3877. helpers.convert_mapping_to_xml(
  3878. reporter, data, mappings, fail_required=True)
  3879. if 'days-to-keep' in data or 'num-to-keep' in data:
  3880. logrotator = XML.SubElement(reporter, 'logRotator')
  3881. mappings = [
  3882. ('days-to-keep', 'daysToKeep', -1),
  3883. ('num-to-keep', 'numToKeep', -1),
  3884. # hardcoded to -1 to emulate what the build publisher
  3885. # plugin seem to do.
  3886. ('', 'artifactDaysToKeep', -1),
  3887. ('', 'artifactNumToKeep', -1)
  3888. ]
  3889. helpers.convert_mapping_to_xml(
  3890. logrotator, data, mappings, fail_required=True)
  3891. def stash(registry, xml_parent, data):
  3892. """yaml: stash
  3893. This plugin will configure the Jenkins Stash Notifier plugin to
  3894. notify Atlassian Stash after job completes.
  3895. Requires the Jenkins :jenkins-wiki:`StashNotifier Plugin
  3896. <StashNotifier+Plugin>`.
  3897. :arg string url: Base url of Stash Server (default "")
  3898. :arg string username: Username of Stash Server (default "")
  3899. :arg string password: Password of Stash Server (default "")
  3900. :arg string credentials-id: Credentials of Stash Server (optional)
  3901. :arg bool ignore-ssl: Ignore unverified SSL certificate (default false)
  3902. :arg string commit-sha1: Commit SHA1 to notify (default "")
  3903. :arg bool include-build-number: Include build number in key
  3904. (default false)
  3905. Minimal Example:
  3906. .. literalinclude:: /../../tests/publishers/fixtures/stash-minimal.yaml
  3907. :language: yaml
  3908. Full Example:
  3909. .. literalinclude:: /../../tests/publishers/fixtures/stash-full.yaml
  3910. :language: yaml
  3911. """
  3912. top = XML.SubElement(xml_parent,
  3913. 'org.jenkinsci.plugins.stashNotifier.StashNotifier')
  3914. XML.SubElement(top, 'stashServerBaseUrl').text = data.get('url', '')
  3915. if data.get('credentials-id') is not None:
  3916. XML.SubElement(top, 'credentialsId').text = str(
  3917. data.get('credentials-id'))
  3918. else:
  3919. XML.SubElement(top, 'stashUserName'
  3920. ).text = helpers.get_value_from_yaml_or_config_file(
  3921. 'username', 'stash', data, registry.jjb_config)
  3922. XML.SubElement(top, 'stashUserPassword'
  3923. ).text = helpers.get_value_from_yaml_or_config_file(
  3924. 'password', 'stash', data, registry.jjb_config)
  3925. mappings = [
  3926. ('ignore-ssl', 'ignoreUnverifiedSSLPeer', False),
  3927. ('commit-sha1', 'commitSha1', ''),
  3928. ('include-build-number', 'includeBuildNumberInKey', False)
  3929. ]
  3930. helpers.convert_mapping_to_xml(
  3931. top, data, mappings, fail_required=True)
  3932. def dependency_check(registry, xml_parent, data):
  3933. """yaml: dependency-check
  3934. Dependency-Check is an open source utility that identifies project
  3935. dependencies and checks if there are any known, publicly disclosed,
  3936. vulnerabilities.
  3937. Requires the Jenkins :jenkins-wiki:`OWASP Dependency-Check Plugin
  3938. <OWASP+Dependency-Check+Plugin>`.
  3939. :arg str pattern: Report filename pattern (optional)
  3940. :arg bool can-run-on-failed: Also runs for failed builds, instead of just
  3941. stable or unstable builds (default false)
  3942. :arg bool should-detect-modules: Determines if Ant or Maven modules should
  3943. be detected for all files that contain warnings (default false)
  3944. :arg int healthy: Sunny threshold (optional)
  3945. :arg int unhealthy: Stormy threshold (optional)
  3946. :arg str health-threshold: Threshold priority for health status
  3947. ('low', 'normal' or 'high', defaulted to 'low')
  3948. :arg dict thresholds: Mark build as failed or unstable if the number of
  3949. errors exceeds a threshold. (optional)
  3950. :thresholds:
  3951. * **unstable** (`dict`)
  3952. :unstable: * **total-all** (`int`)
  3953. * **total-high** (`int`)
  3954. * **total-normal** (`int`)
  3955. * **total-low** (`int`)
  3956. * **new-all** (`int`)
  3957. * **new-high** (`int`)
  3958. * **new-normal** (`int`)
  3959. * **new-low** (`int`)
  3960. * **failed** (`dict`)
  3961. :failed: * **total-all** (`int`)
  3962. * **total-high** (`int`)
  3963. * **total-normal** (`int`)
  3964. * **total-low** (`int`)
  3965. * **new-all** (`int`)
  3966. * **new-high** (`int`)
  3967. * **new-normal** (`int`)
  3968. * **new-low** (`int`)
  3969. :arg str default-encoding: Encoding for parsing or showing files (optional)
  3970. :arg bool do-not-resolve-relative-paths: (default false)
  3971. :arg bool dont-compute-new: If set to false, computes new warnings based on
  3972. the reference build (default true)
  3973. :arg bool use-previous-build-as-reference: determines whether to always
  3974. use the previous build as the reference build (default false)
  3975. :arg bool use-stable-build-as-reference: The number of new warnings will be
  3976. calculated based on the last stable build, allowing reverts of unstable
  3977. builds where the number of warnings was decreased. (default false)
  3978. :arg bool use-delta-values: If set then the number of new warnings is
  3979. calculated by subtracting the total number of warnings of the current
  3980. build from the reference build.
  3981. (default false)
  3982. Minimal Example:
  3983. .. literalinclude::
  3984. /../../tests/publishers/fixtures/dependency-check-minimal.yaml
  3985. :language: yaml
  3986. Full Example:
  3987. .. literalinclude::
  3988. /../../tests/publishers/fixtures/dependency-check-full.yaml
  3989. :language: yaml
  3990. """
  3991. dependency_check = XML.SubElement(
  3992. xml_parent,
  3993. 'org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher')
  3994. # trends
  3995. helpers.build_trends_publisher(
  3996. '[DEPENDENCYCHECK] ', dependency_check, data)
  3997. def description_setter(registry, xml_parent, data):
  3998. """yaml: description-setter
  3999. This plugin sets the description for each build,
  4000. based upon a RegEx test of the build log file.
  4001. Requires the Jenkins :jenkins-wiki:`Description Setter Plugin
  4002. <Description+Setter+Plugin>`.
  4003. :arg str regexp: A RegEx which is used to scan the build log file
  4004. (default '')
  4005. :arg str regexp-for-failed: A RegEx which is used for failed builds
  4006. (default '')
  4007. :arg str description: The description to set on the build (optional)
  4008. :arg str description-for-failed: The description to set on
  4009. the failed builds (optional)
  4010. :arg bool set-for-matrix: Also set the description on
  4011. a multi-configuration build (default false)
  4012. Minimal Example:
  4013. .. literalinclude::
  4014. /../../tests/publishers/fixtures/description-setter-minimal.yaml
  4015. :language: yaml
  4016. Full Example:
  4017. .. literalinclude::
  4018. /../../tests/publishers/fixtures/description-setter-full.yaml
  4019. :language: yaml
  4020. """
  4021. descriptionsetter = XML.SubElement(
  4022. xml_parent,
  4023. 'hudson.plugins.descriptionsetter.DescriptionSetterPublisher')
  4024. mappings = [
  4025. ('regexp', 'regexp', ''),
  4026. ('regexp-for-failed', 'regexpForFailed', ''),
  4027. ('description', 'description', None),
  4028. ('description-for-failed', 'descriptionForFailed', None),
  4029. ('set-for-matrix', 'setForMatrix', False)
  4030. ]
  4031. helpers.convert_mapping_to_xml(
  4032. descriptionsetter, data, mappings, fail_required=False)
  4033. def doxygen(registry, xml_parent, data):
  4034. """yaml: doxygen
  4035. This plugin parses the Doxygen descriptor (Doxyfile) and provides a link to
  4036. the generated Doxygen documentation.
  4037. Requires the Jenkins :jenkins-wiki:`Doxygen Plugin <Doxygen+Plugin>`.
  4038. :arg str doxyfile: The doxyfile path (required)
  4039. :arg str slave: The node or label to pull the doxygen HTML files from
  4040. (default '')
  4041. :arg bool keep-all: Retain doxygen generation for each successful build
  4042. (default false)
  4043. :arg str folder: Folder where you run doxygen (default '')
  4044. Minimal Example:
  4045. .. literalinclude:: /../../tests/publishers/fixtures/doxygen-minimal.yaml
  4046. :language: yaml
  4047. Full Example:
  4048. .. literalinclude:: /../../tests/publishers/fixtures/doxygen-full.yaml
  4049. :language: yaml
  4050. """
  4051. logger = logging.getLogger(__name__)
  4052. p = XML.SubElement(xml_parent, 'hudson.plugins.doxygen.DoxygenArchiver')
  4053. mappings = [
  4054. ('doxyfile', 'doxyfilePath', None),
  4055. ('slave', 'runOnChild', ''),
  4056. ('folder', 'folderWhereYouRunDoxygen', '')
  4057. ]
  4058. helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
  4059. # backward compatibility
  4060. if 'keepall' in data:
  4061. if 'keep-all' in data:
  4062. XML.SubElement(p, 'keepAll').text = str(
  4063. data.get('keep-all', False)).lower()
  4064. logger.warning("The value of 'keepall' will be ignored "
  4065. "in preference to 'keep-all'.")
  4066. else:
  4067. XML.SubElement(p, 'keepAll').text = str(
  4068. data.get('keepall', False)).lower()
  4069. logger.warning("'keepall' is deprecated please use 'keep-all'")
  4070. else:
  4071. XML.SubElement(p, 'keepAll').text = str(
  4072. data.get('keep-all', False)).lower()
  4073. def sitemonitor(registry, xml_parent, data):
  4074. """yaml: sitemonitor
  4075. This plugin checks the availability of an url.
  4076. It requires the :jenkins-wiki:`sitemonitor plugin <SiteMonitor+Plugin>`.
  4077. :arg list sites: List of URLs to check
  4078. Minimal Example:
  4079. .. literalinclude::
  4080. /../../tests/publishers/fixtures/sitemonitor-minimal.yaml
  4081. :language: yaml
  4082. Full Example:
  4083. .. literalinclude:: /../../tests/publishers/fixtures/sitemonitor-full.yaml
  4084. :language: yaml
  4085. """
  4086. mon = XML.SubElement(xml_parent,
  4087. 'hudson.plugins.sitemonitor.SiteMonitorRecorder')
  4088. if data.get('sites'):
  4089. sites = XML.SubElement(mon, 'mSites')
  4090. for siteurl in data.get('sites'):
  4091. site = XML.SubElement(sites,
  4092. 'hudson.plugins.sitemonitor.model.Site')
  4093. XML.SubElement(site, 'mUrl').text = siteurl['url']
  4094. def testng(registry, xml_parent, data):
  4095. """yaml: testng
  4096. This plugin publishes TestNG test reports.
  4097. Requires the Jenkins :jenkins-wiki:`TestNG Results Plugin <testng-plugin>`.
  4098. :arg str pattern: filename pattern to locate the TestNG XML report files
  4099. (required)
  4100. :arg bool escape-test-description: escapes the description string
  4101. associated with the test method while displaying test method details
  4102. (default true)
  4103. :arg bool escape-exception-msg: escapes the test method's exception
  4104. messages. (default true)
  4105. :arg bool fail-on-failed-test-config: Allows for a distinction between
  4106. failing tests and failing configuration methods (>=1.10) (default
  4107. false)
  4108. :arg bool show-failed-builds: include results from failed builds in the
  4109. trend graph (>=1.6) (default false)
  4110. :arg int unstable-skips: Build is marked UNSTABLE if the number/percentage
  4111. of skipped tests exceeds the specified threshold (>=1.11) (default 100)
  4112. :arg int unstable-fails: Build is marked UNSTABLE if the number/percentage
  4113. of failed tests exceeds the specified threshold (>=1.11) (default 0)
  4114. :arg int failed-skips: Build is marked FAILURE if the number/percentage of
  4115. skipped tests exceeds the specified threshold (>=1.11) (default 100)
  4116. :arg int failed-fails: Build is marked FAILURE if the number/percentage of
  4117. failed tests exceeds the specified threshold (>=1.11) (default 100)
  4118. :arg str threshold-mode: Interpret threshold as number of tests or
  4119. percentage of tests (>=1.11) (default percentage)
  4120. Full Example:
  4121. .. literalinclude:: /../../tests/publishers/fixtures/testng-full.yaml
  4122. :language: yaml
  4123. Minimal Example:
  4124. .. literalinclude:: /../../tests/publishers/fixtures/testng-minimal.yaml
  4125. :language: yaml
  4126. """
  4127. reporter = XML.SubElement(xml_parent, 'hudson.plugins.testng.Publisher')
  4128. reporter.set('plugin', 'testng-plugin')
  4129. threshold_modes = {
  4130. 'number': 1,
  4131. 'percentage': 2}
  4132. mappings = [
  4133. ('pattern', 'reportFilenamePattern', None),
  4134. ('escape-test-description', 'escapeTestDescp', True),
  4135. ('escape-exception-msg', 'escapeExceptionMsg', True),
  4136. ('fail-on-failed-test-config', 'failureOnFailedTestConfig', False),
  4137. ('show-failed-builds', 'showFailedBuilds', False),
  4138. ('unstable-skips', 'unstableSkips', 100),
  4139. ('unstable-fails', 'unstableFails', 0),
  4140. ('failed-skips', 'failedSkips', 100),
  4141. ('failed-fails', 'failedFails', 100),
  4142. ('threshold-mode', 'thresholdMode', 'percentage', threshold_modes)
  4143. ]
  4144. helpers.convert_mapping_to_xml(
  4145. reporter, data, mappings, fail_required=True)
  4146. def artifact_deployer(registry, xml_parent, data):
  4147. """yaml: artifact-deployer
  4148. This plugin makes it possible to copy artifacts to remote locations.
  4149. Requires the Jenkins :jenkins-wiki:`ArtifactDeployer Plugin
  4150. <ArtifactDeployer+Plugin>`.
  4151. :arg list entries:
  4152. :entries:
  4153. * **files** (`str`) - files to deploy
  4154. * **basedir** (`str`) - the dir from files are deployed
  4155. * **excludes** (`str`) - the mask to exclude files
  4156. * **remote** (`str`) - a remote output directory
  4157. * **flatten** (`bool`) - ignore the source directory structure
  4158. (default false)
  4159. * **delete-remote** (`bool`) - clean-up remote directory
  4160. before deployment (default false)
  4161. * **delete-remote-artifacts** (`bool`) - delete remote artifacts
  4162. when the build is deleted (default false)
  4163. * **fail-no-files** (`bool`) - fail build if there are no files
  4164. (default false)
  4165. * **groovy-script** (`str`) - execute a Groovy script
  4166. before a build is deleted
  4167. :arg bool deploy-if-fail: Deploy if the build is failed (default false)
  4168. Example:
  4169. .. literalinclude:: /../../tests/publishers/fixtures/artifact-dep.yaml
  4170. :language: yaml
  4171. """
  4172. deployer = XML.SubElement(xml_parent,
  4173. 'org.jenkinsci.plugins.artifactdeployer.'
  4174. 'ArtifactDeployerPublisher')
  4175. if data is None or 'entries' not in data:
  4176. raise Exception('entries field is missing')
  4177. elif data.get('entries', None) is None:
  4178. entries = XML.SubElement(deployer, 'entries', {'class': 'empty-list'})
  4179. else:
  4180. entries = XML.SubElement(deployer, 'entries')
  4181. for entry in data.get('entries'):
  4182. deployer_entry = XML.SubElement(
  4183. entries,
  4184. 'org.jenkinsci.plugins.artifactdeployer.ArtifactDeployerEntry')
  4185. XML.SubElement(deployer_entry, 'includes').text = \
  4186. entry.get('files')
  4187. XML.SubElement(deployer_entry, 'basedir').text = \
  4188. entry.get('basedir')
  4189. XML.SubElement(deployer_entry, 'excludes').text = \
  4190. entry.get('excludes')
  4191. XML.SubElement(deployer_entry, 'remote').text = entry.get('remote')
  4192. XML.SubElement(deployer_entry, 'flatten').text = \
  4193. str(entry.get('flatten', False)).lower()
  4194. XML.SubElement(deployer_entry, 'deleteRemote').text = \
  4195. str(entry.get('delete-remote', False)).lower()
  4196. XML.SubElement(deployer_entry, 'deleteRemoteArtifacts').text = \
  4197. str(entry.get('delete-remote-artifacts', False)).lower()
  4198. XML.SubElement(deployer_entry, 'failNoFilesDeploy').text = \
  4199. str(entry.get('fail-no-files', False)).lower()
  4200. XML.SubElement(deployer_entry, 'groovyExpression').text = \
  4201. entry.get('groovy-script')
  4202. deploy_if_fail = str(data.get('deploy-if-fail', False)).lower()
  4203. XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail
  4204. def s3(registry, xml_parent, data):
  4205. """yaml: s3
  4206. Upload build artifacts to Amazon S3.
  4207. Requires the Jenkins :jenkins-wiki:`S3 plugin <S3+Plugin>`.
  4208. :arg str s3-profile: Globally-defined S3 profile to use
  4209. :arg list entries:
  4210. :entries:
  4211. * **destination-bucket** (`str`) - Destination S3 bucket
  4212. * **source-files** (`str`) - Source files (Ant glob syntax)
  4213. * **storage-class** (`str`) - S3 storage class; one of "STANDARD"
  4214. or "REDUCED_REDUNDANCY"
  4215. * **bucket-region** (`str`) - S3 bucket region (capitalized with
  4216. underscores)
  4217. * **upload-on-failure** (`bool`) - Upload files even if the build
  4218. failed (default false)
  4219. * **upload-from-slave** (`bool`) - Perform the upload directly from
  4220. the Jenkins slave rather than the master node. (default false)
  4221. * **managed-artifacts** (`bool`) - Let Jenkins fully manage the
  4222. published artifacts, similar to when artifacts are published to
  4223. the Jenkins master. (default false)
  4224. * **s3-encryption** (`bool`) - Use S3 AES-256 server side encryption
  4225. support. (default false)
  4226. * **flatten** (`bool`) - Ignore the directory structure of the
  4227. artifacts in the source project and copy all matching artifacts
  4228. directly into the specified bucket. (default false)
  4229. * **dont-wait-for-concurrent-builds** (`bool`) - Don't wait
  4230. for completion of concurrent builds before publishing to S3
  4231. (default false)
  4232. :arg list metadata-tags:
  4233. :metadata-tags:
  4234. * **key** Metadata key for files from this build. It will be
  4235. prefixed by "x-amz-meta-" when uploaded to S3. Can contain macros
  4236. (e.g. environment variables).
  4237. * **value** Metadata value associated with the key. Can contain macros.
  4238. Example:
  4239. .. literalinclude:: /../../tests/publishers/fixtures/s3001.yaml
  4240. :language: yaml
  4241. """
  4242. deployer = XML.SubElement(xml_parent,
  4243. 'hudson.plugins.s3.S3BucketPublisher')
  4244. if data is None or not data.get('entries'):
  4245. raise JenkinsJobsException('No filesets defined.')
  4246. XML.SubElement(deployer, 'profileName').text = data.get('s3-profile')
  4247. entries = XML.SubElement(deployer, 'entries')
  4248. for entry in data.get('entries'):
  4249. fileset = XML.SubElement(entries, 'hudson.plugins.s3.Entry')
  4250. # xml keys -> yaml keys
  4251. settings = [('bucket', 'destination-bucket', ''),
  4252. ('sourceFile', 'source-files', ''),
  4253. ('storageClass', 'storage-class', ''),
  4254. ('selectedRegion', 'bucket-region', ''),
  4255. ('noUploadOnFailure', 'upload-on-failure', False),
  4256. ('uploadFromSlave', 'upload-from-slave', False),
  4257. ('managedArtifacts', 'managed-artifacts', False),
  4258. ('useServerSideEncryption', 's3-encryption', False),
  4259. ('flatten', 'flatten', False),
  4260. ('dontWaitForConcurrentBuildCompletion',
  4261. 'dont-wait-for-concurrent-builds', False)]
  4262. for xml_key, yaml_key, default in settings:
  4263. xml_config = XML.SubElement(fileset, xml_key)
  4264. config_value = entry.get(yaml_key, default)
  4265. if xml_key == 'noUploadOnFailure':
  4266. xml_config.text = str(not config_value).lower()
  4267. elif isinstance(default, bool):
  4268. xml_config.text = str(config_value).lower()
  4269. else:
  4270. xml_config.text = str(config_value)
  4271. metadata = XML.SubElement(deployer, 'userMetadata')
  4272. for tag in data.get('metadata-tags', []):
  4273. pair = XML.SubElement(metadata, 'hudson.plugins.s3.MetadataPair')
  4274. XML.SubElement(pair, 'key').text = tag.get('key')
  4275. XML.SubElement(pair, 'value').text = tag.get('value')
  4276. def ruby_metrics(registry, xml_parent, data):
  4277. """yaml: ruby-metrics
  4278. Rcov plugin parses rcov html report files and
  4279. shows it in Jenkins with a trend graph.
  4280. Requires the Jenkins :jenkins-wiki:`Ruby metrics plugin
  4281. <RubyMetrics+plugin>`.
  4282. :arg str report-dir: Relative path to the coverage report directory
  4283. :arg dict targets:
  4284. :targets: (total-coverage, code-coverage)
  4285. * **healthy** (`int`): Healthy threshold
  4286. * **unhealthy** (`int`): Unhealthy threshold
  4287. * **unstable** (`int`): Unstable threshold
  4288. Example:
  4289. .. literalinclude:: /../../tests/publishers/fixtures/ruby-metrics.yaml
  4290. :language: yaml
  4291. """
  4292. metrics = XML.SubElement(
  4293. xml_parent,
  4294. 'hudson.plugins.rubyMetrics.rcov.RcovPublisher')
  4295. report_dir = data.get('report-dir', '')
  4296. XML.SubElement(metrics, 'reportDir').text = report_dir
  4297. targets = XML.SubElement(metrics, 'targets')
  4298. if 'target' in data:
  4299. for t in data['target']:
  4300. if not ('code-coverage' in t or 'total-coverage' in t):
  4301. raise JenkinsJobsException('Unrecognized target name')
  4302. el = XML.SubElement(
  4303. targets,
  4304. 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget')
  4305. if 'total-coverage' in t:
  4306. XML.SubElement(el, 'metric').text = 'TOTAL_COVERAGE'
  4307. else:
  4308. XML.SubElement(el, 'metric').text = 'CODE_COVERAGE'
  4309. for threshold_name, threshold_value in \
  4310. next(iter(t.values())).items():
  4311. elname = threshold_name.lower()
  4312. XML.SubElement(el, elname).text = str(threshold_value)
  4313. else:
  4314. raise JenkinsJobsException('Coverage metric targets must be set')
  4315. def fitnesse(registry, xml_parent, data):
  4316. """yaml: fitnesse
  4317. Publish Fitnesse test results
  4318. Requires the Jenkins :jenkins-wiki:`Fitnesse plugin <Fitnesse+Plugin>`.
  4319. :arg str results: path specifier for results files
  4320. Example:
  4321. .. literalinclude:: /../../tests/publishers/fixtures/fitnesse001.yaml
  4322. :language: yaml
  4323. """
  4324. fitnesse = XML.SubElement(
  4325. xml_parent,
  4326. 'hudson.plugins.fitnesse.FitnesseResultsRecorder')
  4327. results = data.get('results', '')
  4328. XML.SubElement(fitnesse, 'fitnessePathToXmlResultsIn').text = results
  4329. def valgrind(registry, xml_parent, data):
  4330. """yaml: valgrind
  4331. This plugin publishes Valgrind Memcheck XML results.
  4332. Requires the Jenkins :jenkins-wiki:`Valgrind Plugin <Valgrind+Plugin>`.
  4333. :arg str pattern: Filename pattern to locate the Valgrind XML report files
  4334. (required)
  4335. :arg dict thresholds: Mark build as failed or unstable if the number of
  4336. errors exceeds a threshold. All threshold values are optional.
  4337. :thresholds:
  4338. * **unstable** (`dict`)
  4339. :unstable: * **invalid-read-write** (`int`)
  4340. * **definitely-lost** (`int`)
  4341. * **total** (`int`)
  4342. * **failed** (`dict`)
  4343. :failed: * **invalid-read-write** (`int`)
  4344. * **definitely-lost** (`int`)
  4345. * **total** (`int`)
  4346. :arg bool fail-no-reports: Fail build if no reports are found
  4347. (default false)
  4348. :arg bool fail-invalid-reports: Fail build if reports are malformed
  4349. (default false)
  4350. :arg bool publish-if-aborted: Publish results for aborted builds
  4351. (default false)
  4352. :arg bool publish-if-failed: Publish results for failed builds
  4353. (default false)
  4354. Example:
  4355. .. literalinclude:: /../../tests/publishers/fixtures/valgrind001.yaml
  4356. :language: yaml
  4357. """
  4358. p = XML.SubElement(xml_parent,
  4359. 'org.jenkinsci.plugins.valgrind.ValgrindPublisher')
  4360. p = XML.SubElement(p, 'valgrindPublisherConfig')
  4361. if 'pattern' not in data:
  4362. raise JenkinsJobsException("A filename pattern must be specified.")
  4363. XML.SubElement(p, 'pattern').text = data['pattern']
  4364. dthresholds = data.get('thresholds', {})
  4365. for threshold in ['unstable', 'failed']:
  4366. dthreshold = dthresholds.get(threshold, {})
  4367. threshold = threshold.replace('failed', 'fail')
  4368. ThresholdInvalidReadWrite = '%sThresholdInvalidReadWrite' % threshold
  4369. ThresholdDefinitelyLost = '%sThresholdDefinitelyLost' % threshold
  4370. ThresholdTotal = '%sThresholdTotal' % threshold
  4371. threshold_mapping = [
  4372. ('invalid-read-write', ThresholdInvalidReadWrite, ''),
  4373. ('definitely-lost', ThresholdDefinitelyLost, ''),
  4374. ('total', ThresholdTotal, ''),
  4375. ]
  4376. helpers.convert_mapping_to_xml(
  4377. p, dthreshold, threshold_mapping, fail_required=True)
  4378. mapping = [
  4379. ('fail-no-reports', 'failBuildOnMissingReports', False),
  4380. ('fail-invalid-reports', 'failBuildOnInvalidReports', False),
  4381. ('publish-if-aborted', 'publishResultsForAbortedBuilds', False),
  4382. ('publish-if-failed', 'publishResultsForFailedBuilds', False),
  4383. ]
  4384. helpers.convert_mapping_to_xml(p, data, mapping, fail_required=True)
  4385. def pmd(registry, xml_parent, data):
  4386. """yaml: pmd
  4387. Publish trend reports with PMD.
  4388. Requires the Jenkins :jenkins-wiki:`PMD Plugin <PMD+Plugin>`.
  4389. The PMD component accepts a dictionary with the following values:
  4390. :arg str pattern: Report filename pattern (optional)
  4391. :arg bool can-run-on-failed: Also runs for failed builds, instead of just
  4392. stable or unstable builds (default false)
  4393. :arg bool should-detect-modules: Determines if Ant or Maven modules should
  4394. be detected for all files that contain warnings (default false)
  4395. :arg int healthy: Sunny threshold (optional)
  4396. :arg int unhealthy: Stormy threshold (optional)
  4397. :arg str health-threshold: Threshold priority for health status
  4398. ('low', 'normal' or 'high', defaulted to 'low')
  4399. :arg dict thresholds: Mark build as failed or unstable if the number of
  4400. errors exceeds a threshold. (optional)
  4401. :thresholds:
  4402. * **unstable** (`dict`)
  4403. :unstable: * **total-all** (`int`)
  4404. * **total-high** (`int`)
  4405. * **total-normal** (`int`)
  4406. * **total-low** (`int`)
  4407. * **new-all** (`int`)
  4408. * **new-high** (`int`)
  4409. * **new-normal** (`int`)
  4410. * **new-low** (`int`)
  4411. * **failed** (`dict`)
  4412. :failed: * **total-all** (`int`)
  4413. * **total-high** (`int`)
  4414. * **total-normal** (`int`)
  4415. * **total-low** (`int`)
  4416. * **new-all** (`int`)
  4417. * **new-high** (`int`)
  4418. * **new-normal** (`int`)
  4419. * **new-low** (`int`)
  4420. :arg str default-encoding: Encoding for parsing or showing files (optional)
  4421. :arg bool do-not-resolve-relative-paths: (default false)
  4422. :arg bool dont-compute-new: If set to false, computes new warnings based on
  4423. the reference build (default true)
  4424. :arg bool use-previous-build-as-reference: determines whether to always
  4425. use the previous build as the reference build (default false)
  4426. :arg bool use-stable-build-as-reference: The number of new warnings will be
  4427. calculated based on the last stable build, allowing reverts of unstable
  4428. builds where the number of warnings was decreased. (default false)
  4429. :arg bool use-delta-values: If set then the number of new warnings is
  4430. calculated by subtracting the total number of warnings of the current
  4431. build from the reference build.
  4432. (default false)
  4433. Example:
  4434. .. literalinclude:: /../../tests/publishers/fixtures/pmd001.yaml
  4435. :language: yaml
  4436. Full example:
  4437. .. literalinclude:: /../../tests/publishers/fixtures/pmd002.yaml
  4438. :language: yaml
  4439. """
  4440. xml_element = XML.SubElement(xml_parent, 'hudson.plugins.pmd.PmdPublisher')
  4441. helpers.build_trends_publisher('[PMD] ', xml_element, data)
  4442. def scan_build(registry, xml_parent, data):
  4443. """yaml: scan-build
  4444. Publishes results from the Clang scan-build static analyzer.
  4445. The scan-build report has to be generated in the directory
  4446. ``${WORKSPACE}/clangScanBuildReports`` for the publisher to find it.
  4447. Requires the Jenkins :jenkins-wiki:`Clang Scan-Build Plugin
  4448. <Clang+Scan-Build+Plugin>`.
  4449. :arg bool mark-unstable: Mark build as unstable if the number of bugs
  4450. exceeds a threshold (default false)
  4451. :arg int threshold: Threshold for marking builds as unstable (default 0)
  4452. :arg string exclude-paths: Comma separated paths to exclude from reports
  4453. (>=1.5) (default '')
  4454. :arg string report-folder: Folder where generated reports are located
  4455. (>=1.7) (default 'clangScanBuildReports')
  4456. Full Example:
  4457. .. literalinclude:: /../../tests/publishers/fixtures/scan-build-full.yaml
  4458. :language: yaml
  4459. Minimal Example:
  4460. .. literalinclude::
  4461. /../../tests/publishers/fixtures/scan-build-minimal.yaml
  4462. :language: yaml
  4463. """
  4464. p = XML.SubElement(
  4465. xml_parent,
  4466. 'jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher')
  4467. p.set('plugin', 'clang-scanbuild')
  4468. mappings = [
  4469. ('mark-unstable', 'markBuildUnstableWhenThresholdIsExceeded', False),
  4470. ('threshold', 'bugThreshold', 0),
  4471. ('exclude-paths', 'clangexcludedpaths', ''),
  4472. ('report-folder', 'reportFolderName', 'clangScanBuildReports'),
  4473. ]
  4474. helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
  4475. def dry(registry, xml_parent, data):
  4476. """yaml: dry
  4477. Publish trend reports with DRY.
  4478. Requires the Jenkins :jenkins-wiki:`DRY Plugin <DRY+Plugin>`.
  4479. The DRY component accepts a dictionary with the following values:
  4480. :arg str pattern: Report filename pattern (default '')
  4481. :arg bool can-run-on-failed: Also runs for failed builds, instead of just
  4482. stable or unstable builds (default false)
  4483. :arg bool should-detect-modules: Determines if Ant or Maven modules should
  4484. be detected for all files that contain warnings (default false)
  4485. :arg int healthy: Sunny threshold (default '')
  4486. :arg int unhealthy: Stormy threshold (default '')
  4487. :arg str health-threshold: Threshold priority for health status
  4488. ('low', 'normal' or 'high', defaulted to 'low')
  4489. :arg int high-threshold: Minimum number of duplicated lines for high
  4490. priority warnings. (default 50)
  4491. :arg int normal-threshold: Minimum number of duplicated lines for normal
  4492. priority warnings. (default 25)
  4493. :arg dict thresholds: Mark build as failed or unstable if the number of
  4494. errors exceeds a threshold. (default '')
  4495. :thresholds:
  4496. * **unstable** (`dict`)
  4497. :unstable: * **total-all** (`int`)
  4498. * **total-high** (`int`)
  4499. * **total-normal** (`int`)
  4500. * **total-low** (`int`)
  4501. * **new-all** (`int`)
  4502. * **new-high** (`int`)
  4503. * **new-normal** (`int`)
  4504. * **new-low** (`int`)
  4505. * **failed** (`dict`)
  4506. :failed: * **total-all** (`int`)
  4507. * **total-high** (`int`)
  4508. * **total-normal** (`int`)
  4509. * **total-low** (`int`)
  4510. * **new-all** (`int`)
  4511. * **new-high** (`int`)
  4512. * **new-normal** (`int`)
  4513. * **new-low** (`int`)
  4514. :arg str default-encoding: Encoding for parsing or showing files (optional)
  4515. :arg bool do-not-resolve-relative-paths: (default false)
  4516. :arg bool dont-compute-new: If set to false, computes new warnings based on
  4517. the reference build (default true)
  4518. :arg bool use-previous-build-as-reference: determines whether to always
  4519. use the previous build as the reference build (default false)
  4520. :arg bool use-stable-build-as-reference: The number of new warnings will be
  4521. calculated based on the last stable build, allowing reverts of unstable
  4522. builds where the number of warnings was decreased. (default false)
  4523. :arg bool use-delta-values: If set then the number of new warnings is
  4524. calculated by subtracting the total number of warnings of the current
  4525. build from the reference build. (default false)
  4526. Example:
  4527. .. literalinclude:: /../../tests/publishers/fixtures/dry001.yaml
  4528. :language: yaml
  4529. Full example:
  4530. .. literalinclude:: /../../tests/publishers/fixtures/dry004.yaml
  4531. :language: yaml
  4532. """
  4533. xml_element = XML.SubElement(xml_parent, 'hudson.plugins.dry.DryPublisher')
  4534. helpers.build_trends_publisher('[DRY] ', xml_element, data)
  4535. # Add specific settings for this trends publisher
  4536. settings = [
  4537. ('high-threshold', 'highThreshold', 50),
  4538. ('normal-threshold', 'normalThreshold', 25)]
  4539. helpers.convert_mapping_to_xml(
  4540. xml_element, data, settings, fail_required=True)
  4541. def shining_panda(registry, xml_parent, data):
  4542. """yaml: shining-panda
  4543. Publish coverage.py results. Requires the Jenkins
  4544. :jenkins-wiki:`ShiningPanda Plugin <ShiningPanda+Plugin>`.
  4545. :arg str html-reports-directory: path to coverage.py html results
  4546. (optional)
  4547. Example:
  4548. .. literalinclude:: /../../tests/publishers/fixtures/shiningpanda001.yaml
  4549. :language: yaml
  4550. """
  4551. shining_panda_plugin = XML.SubElement(
  4552. xml_parent,
  4553. 'jenkins.plugins.shiningpanda.publishers.CoveragePublisher')
  4554. mapping = [('html-reports-directory', 'htmlDir', None)]
  4555. helpers.convert_mapping_to_xml(
  4556. shining_panda_plugin, data, mapping, fail_required=False)
  4557. def downstream_ext(registry, xml_parent, data):
  4558. """yaml: downstream-ext
  4559. Trigger multiple downstream jobs when a job is completed and
  4560. condition is met.
  4561. Requires the Jenkins :jenkins-wiki:`Downstream-Ext Plugin
  4562. <Downstream-Ext+Plugin>`.
  4563. :arg list projects: Projects to build (required)
  4564. :arg string condition: comparison condition used for the criteria.
  4565. One of 'equal-or-over', 'equal-or-under', 'equal'
  4566. (default 'equal-or-over')
  4567. :arg string criteria: Trigger downstream job if build results meets
  4568. condition. One of 'success', 'unstable', 'failure' or
  4569. 'aborted' (default 'success')
  4570. :arg bool only-on-scm-change: Trigger only if downstream project
  4571. has SCM changes (default false)
  4572. :arg bool only-on-local-scm-change: Trigger only if current project
  4573. has SCM changes (default false)
  4574. Example:
  4575. .. literalinclude::
  4576. /../../tests/publishers/fixtures/downstream-ext002.yaml
  4577. :language: yaml
  4578. """
  4579. conditions = {
  4580. "equal-or-over": "AND_HIGHER",
  4581. "equal-or-under": "AND_LOWER",
  4582. "equal": "EXACT"
  4583. }
  4584. p = XML.SubElement(xml_parent,
  4585. 'hudson.plugins.downstream__ext.DownstreamTrigger')
  4586. if 'projects' not in data:
  4587. raise JenkinsJobsException("Missing list of downstream projects.")
  4588. XML.SubElement(p, 'childProjects').text = ','.join(data['projects'])
  4589. th = XML.SubElement(p, 'threshold')
  4590. criteria = data.get('criteria', 'success').upper()
  4591. wr_threshold = hudson_model.THRESHOLDS[
  4592. criteria]
  4593. if criteria not in hudson_model.THRESHOLDS:
  4594. raise JenkinsJobsException("criteria must be one of %s" %
  4595. ", ".join(hudson_model.THRESHOLDS.keys()))
  4596. mapping = [('name', 'name', None),
  4597. ('ordinal', 'ordinal', None),
  4598. ('color', 'color', None),
  4599. ('complete', 'completeBuild', None)]
  4600. helpers.convert_mapping_to_xml(th,
  4601. wr_threshold, mapping, fail_required=True)
  4602. condition_mapping = [('condition',
  4603. 'thresholdStrategy', 'equal-or-over', conditions),
  4604. ('only-on-scm-change', 'onlyIfSCMChanges', False),
  4605. ('only-on-local-scm-change', 'onlyIfLocalSCMChanges', False)]
  4606. helpers.convert_mapping_to_xml(p, data,
  4607. condition_mapping, fail_required=True)
  4608. def rundeck(registry, xml_parent, data):
  4609. """yaml: rundeck
  4610. Trigger a rundeck job when the build is complete.
  4611. Requires the Jenkins :jenkins-wiki:`RunDeck
  4612. Plugin <RunDeck+Plugin>`.
  4613. :arg str job-id: The RunDeck job identifier. (required)
  4614. This could be:
  4615. * ID example : "42"
  4616. * UUID example : "2027ce89-7924-4ecf-a963-30090ada834f"
  4617. * reference, in the format : "project:group/job"
  4618. :arg str options: List of options for the Rundeck job, in Java-Properties
  4619. format: key=value (default "")
  4620. :arg str node-filters: List of filters to optionally filter the nodes
  4621. included by the job. (default "")
  4622. :arg str tag: Used for on-demand job scheduling on rundeck: if a tag is
  4623. specified, the job will only execute if the given tag is present in the
  4624. SCM changelog. (default "")
  4625. :arg bool wait-for-rundeck: If true Jenkins will wait for the job to
  4626. complete, if false the job will be started and Jenkins will move on.
  4627. (default false)
  4628. :arg bool fail-the-build: If true a RunDeck job failure will cause the
  4629. Jenkins build to fail. (default false)
  4630. Example:
  4631. .. literalinclude:: /../../tests/publishers/fixtures/rundeck001.yaml
  4632. :language: yaml
  4633. Full example:
  4634. .. literalinclude:: /../../tests/publishers/fixtures/rundeck002.yaml
  4635. :language: yaml
  4636. """
  4637. p = XML.SubElement(
  4638. xml_parent,
  4639. 'org.jenkinsci.plugins.rundeck.RundeckNotifier')
  4640. mappings = [
  4641. ('job-id', 'jobId', None),
  4642. ('options', 'options', ''),
  4643. ('node-filters', 'nodeFilters', ''),
  4644. ('tag', 'tag', ''),
  4645. ('wait-for-rundeck', 'shouldWaitForRundeckJob', False),
  4646. ('fail-the-build', 'shouldFailTheBuild', False),
  4647. ]
  4648. helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
  4649. def create_publishers(registry, action):
  4650. dummy_parent = XML.Element("dummy")
  4651. registry.dispatch('publisher', dummy_parent, action)
  4652. return list(dummy_parent)
  4653. def conditional_publisher(registry, xml_parent, data):
  4654. """yaml: conditional-publisher
  4655. Conditionally execute some post-build steps. Requires the Jenkins
  4656. :jenkins-wiki:`Flexible Publish Plugin <Flexible+Publish+Plugin>`.
  4657. A Flexible Publish list of Conditional Actions is created in Jenkins.
  4658. :arg str condition-kind: Condition kind that must be verified before the
  4659. action is executed. Valid values and their additional attributes are
  4660. described in the conditions_ table.
  4661. :arg str on-evaluation-failure: What should be the outcome of the build
  4662. if the evaluation of the condition fails. Possible values are `fail`,
  4663. `mark-unstable`, `run-and-mark-unstable`, `run` and `dont-run`.
  4664. Default is `fail`.
  4665. :arg list action: Action to run if the condition is verified. Item
  4666. can be any publisher known by Jenkins Job Builder and supported
  4667. by the Flexible Publish Plugin.
  4668. .. _conditions:
  4669. ================== ====================================================
  4670. Condition kind Description
  4671. ================== ====================================================
  4672. always Condition is always verified
  4673. never Condition is never verified
  4674. boolean-expression Run the action if the expression expands to a
  4675. representation of true
  4676. :condition-expression: Expression to expand
  4677. current-status Run the action if the current build status is
  4678. within the configured range
  4679. :condition-worst: Accepted values are SUCCESS,
  4680. UNSTABLE, FAILURE, NOT_BUILD, ABORTED
  4681. :condition-best: Accepted values are SUCCESS,
  4682. UNSTABLE, FAILURE, NOT_BUILD, ABORTED
  4683. shell Run the action if the shell command succeeds
  4684. :condition-command: Shell command to execute
  4685. windows-shell Similar to shell, except that commands will be
  4686. executed by cmd, under Windows
  4687. :condition-command: Command to execute
  4688. regexp Run the action if a regular expression matches
  4689. :condition-expression: Regular Expression
  4690. :condition-searchtext: Text to match against
  4691. the regular expression
  4692. file-exists Run the action if a file exists
  4693. :condition-filename: Check existence of this file
  4694. :condition-basedir: If condition-filename is
  4695. relative, it will be considered relative to
  4696. either `workspace`, `artifact-directory`,
  4697. or `jenkins-home`. Default is `workspace`.
  4698. ================== ====================================================
  4699. Single Conditional Action Example:
  4700. .. literalinclude:: \
  4701. /../../tests/publishers/fixtures/conditional-publisher001.yaml
  4702. :language: yaml
  4703. Multiple Conditional Actions Example
  4704. (includes example of multiple actions per condition which requires
  4705. v0.13 or higher of the Flexible Publish plugin):
  4706. .. literalinclude:: \
  4707. /../../tests/publishers/fixtures/conditional-publisher003.yaml
  4708. :language: yaml
  4709. :download:`Multiple Conditional Actions Example for pre-v0.13 versions
  4710. <../../tests/publishers/fixtures/conditional-publisher002.yaml>`
  4711. """
  4712. def publish_condition(cdata):
  4713. kind = cdata['condition-kind']
  4714. ctag = XML.SubElement(cond_publisher, condition_tag)
  4715. class_pkg = 'org.jenkins_ci.plugins.run_condition'
  4716. if kind == "always":
  4717. ctag.set('class',
  4718. class_pkg + '.core.AlwaysRun')
  4719. elif kind == "never":
  4720. ctag.set('class',
  4721. class_pkg + '.core.NeverRun')
  4722. elif kind == "boolean-expression":
  4723. ctag.set('class',
  4724. class_pkg + '.core.BooleanCondition')
  4725. XML.SubElement(ctag, "token").text = cdata['condition-expression']
  4726. elif kind == "current-status":
  4727. ctag.set('class',
  4728. class_pkg + '.core.StatusCondition')
  4729. wr = XML.SubElement(ctag, 'worstResult')
  4730. wr_name = cdata['condition-worst']
  4731. if wr_name not in hudson_model.THRESHOLDS:
  4732. raise JenkinsJobsException(
  4733. "threshold must be one of %s" %
  4734. ", ".join(hudson_model.THRESHOLDS.keys()))
  4735. wr_threshold = hudson_model.THRESHOLDS[wr_name]
  4736. XML.SubElement(wr, "name").text = wr_threshold['name']
  4737. XML.SubElement(wr, "ordinal").text = wr_threshold['ordinal']
  4738. XML.SubElement(wr, "color").text = wr_threshold['color']
  4739. XML.SubElement(wr, "completeBuild").text = \
  4740. str(wr_threshold['complete']).lower()
  4741. br = XML.SubElement(ctag, 'bestResult')
  4742. br_name = cdata['condition-best']
  4743. if br_name not in hudson_model.THRESHOLDS:
  4744. raise JenkinsJobsException(
  4745. "threshold must be one of %s" %
  4746. ", ".join(hudson_model.THRESHOLDS.keys()))
  4747. br_threshold = hudson_model.THRESHOLDS[br_name]
  4748. XML.SubElement(br, "name").text = br_threshold['name']
  4749. XML.SubElement(br, "ordinal").text = br_threshold['ordinal']
  4750. XML.SubElement(br, "color").text = br_threshold['color']
  4751. XML.SubElement(br, "completeBuild").text = \
  4752. str(wr_threshold['complete']).lower()
  4753. elif kind == "shell":
  4754. ctag.set('class',
  4755. class_pkg + '.contributed.ShellCondition')
  4756. XML.SubElement(ctag, "command").text = cdata['condition-command']
  4757. elif kind == "windows-shell":
  4758. ctag.set('class',
  4759. class_pkg + '.contributed.BatchFileCondition')
  4760. XML.SubElement(ctag, "command").text = cdata['condition-command']
  4761. elif kind == "regexp":
  4762. ctag.set('class',
  4763. class_pkg + '.core.ExpressionCondition')
  4764. XML.SubElement(ctag,
  4765. "expression").text = cdata['condition-expression']
  4766. XML.SubElement(ctag, "label").text = cdata['condition-searchtext']
  4767. elif kind == "file-exists":
  4768. ctag.set('class',
  4769. class_pkg + '.core.FileExistsCondition')
  4770. XML.SubElement(ctag, "file").text = cdata['condition-filename']
  4771. basedir = cdata.get('condition-basedir', 'workspace')
  4772. basedir_tag = XML.SubElement(ctag, "baseDir")
  4773. if "workspace" == basedir:
  4774. basedir_tag.set('class',
  4775. class_pkg + '.common.BaseDirectory$Workspace')
  4776. elif "artifact-directory" == basedir:
  4777. basedir_tag.set('class',
  4778. class_pkg + '.common.'
  4779. 'BaseDirectory$ArtifactsDir')
  4780. elif "jenkins-home" == basedir:
  4781. basedir_tag.set('class',
  4782. class_pkg + '.common.'
  4783. 'BaseDirectory$JenkinsHome')
  4784. else:
  4785. raise JenkinsJobsException('%s is not a valid condition-kind '
  4786. 'value.' % kind)
  4787. def publish_action(parent, action):
  4788. for edited_node in create_publishers(registry, action):
  4789. if not use_publisher_list:
  4790. edited_node.set('class', edited_node.tag)
  4791. edited_node.tag = 'publisher'
  4792. parent.append(edited_node)
  4793. flex_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
  4794. 'FlexiblePublisher'
  4795. cond_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
  4796. 'ConditionalPublisher'
  4797. root_tag = XML.SubElement(xml_parent, flex_publisher_tag)
  4798. publishers_tag = XML.SubElement(root_tag, "publishers")
  4799. condition_tag = "condition"
  4800. evaluation_classes_pkg = 'org.jenkins_ci.plugins.run_condition'
  4801. evaluation_classes = {
  4802. 'fail': evaluation_classes_pkg + '.BuildStepRunner$Fail',
  4803. 'mark-unstable': evaluation_classes_pkg +
  4804. '.BuildStepRunner$Unstable',
  4805. 'run-and-mark-unstable': evaluation_classes_pkg +
  4806. '.BuildStepRunner$RunUnstable',
  4807. 'run': evaluation_classes_pkg + '.BuildStepRunner$Run',
  4808. 'dont-run': evaluation_classes_pkg + '.BuildStepRunner$DontRun',
  4809. }
  4810. for cond_action in data:
  4811. cond_publisher = XML.SubElement(publishers_tag, cond_publisher_tag)
  4812. publish_condition(cond_action)
  4813. evaluation_flag = cond_action.get('on-evaluation-failure', 'fail')
  4814. if evaluation_flag not in evaluation_classes.keys():
  4815. raise JenkinsJobsException('on-evaluation-failure value '
  4816. 'specified is not valid. Must be one '
  4817. 'of: %s' % evaluation_classes.keys())
  4818. evaluation_class = evaluation_classes[evaluation_flag]
  4819. XML.SubElement(cond_publisher, "runner").set('class',
  4820. evaluation_class)
  4821. if 'action' in cond_action:
  4822. actions = cond_action['action']
  4823. action_parent = cond_publisher
  4824. plugin_info = registry.get_plugin_info("Flexible Publish Plugin")
  4825. # Note: Assume latest version of plugin is preferred config format
  4826. version = pkg_resources.parse_version(
  4827. plugin_info.get('version', str(sys.maxsize)))
  4828. # XML tag changed from publisher to publisherList in v0.13
  4829. # check the plugin version to determine further operations
  4830. use_publisher_list = version >= pkg_resources.parse_version("0.13")
  4831. if use_publisher_list:
  4832. action_parent = XML.SubElement(cond_publisher, 'publisherList')
  4833. else:
  4834. # Check the length of actions list for versions prior to 0.13.
  4835. # Flexible Publish will overwrite action if more than one is
  4836. # specified. Limit the action list to one element.
  4837. if len(actions) is not 1:
  4838. raise JenkinsJobsException("Only one action may be "
  4839. "specified for each condition.")
  4840. for action in actions:
  4841. publish_action(action_parent, action)
  4842. else:
  4843. raise JenkinsJobsException('action must be set for each condition')
  4844. def scoverage(registry, xml_parent, data):
  4845. """yaml: scoverage
  4846. Publish scoverage results as a trend graph.
  4847. Requires the Jenkins :jenkins-wiki:`Scoverage Plugin <Scoverage+Plugin>`.
  4848. :arg str report-directory: This is a directory that specifies the locations
  4849. where the xml scoverage report is generated (required)
  4850. :arg str report-file: This is a file name that is given to the xml
  4851. scoverage report (required)
  4852. Example:
  4853. .. literalinclude:: /../../tests/publishers/fixtures/scoverage001.yaml
  4854. :language: yaml
  4855. """
  4856. scoverage = XML.SubElement(
  4857. xml_parent,
  4858. 'org.jenkinsci.plugins.scoverage.ScoveragePublisher')
  4859. scoverage.set('plugin', 'scoverage')
  4860. mappings = [
  4861. ('report-directory', 'reportDir', None),
  4862. ('report-file', 'reportFile', None),
  4863. ]
  4864. helpers.convert_mapping_to_xml(
  4865. scoverage, data, mappings, fail_required=True)
  4866. def display_upstream_changes(registry, xml_parent, data):
  4867. """yaml: display-upstream-changes
  4868. Display SCM changes of upstream jobs. Requires the Jenkins
  4869. :jenkins-wiki:`Display Upstream Changes Plugin
  4870. <Display+Upstream+Changes+Plugin>`.
  4871. Example:
  4872. .. literalinclude:: \
  4873. /../../tests/publishers/fixtures/display-upstream-changes.yaml
  4874. """
  4875. XML.SubElement(
  4876. xml_parent,
  4877. 'jenkins.plugins.displayupstreamchanges.'
  4878. 'DisplayUpstreamChangesRecorder')
  4879. def gatling(registry, xml_parent, data):
  4880. """yaml: gatling
  4881. Publish gatling results as a trend graph
  4882. Requires the Jenkins :jenkins-wiki:`Gatling Plugin <Gatling+Plugin>`.
  4883. Example:
  4884. .. literalinclude:: /../../tests/publishers/fixtures/gatling001.yaml
  4885. :language: yaml
  4886. """
  4887. gatling = XML.SubElement(
  4888. xml_parent, 'io.gatling.jenkins.GatlingPublisher')
  4889. mapping = [('', 'enabled', 'true')]
  4890. helpers.convert_mapping_to_xml(gatling, data, mapping, fail_required=True)
  4891. def logstash(registry, xml_parent, data):
  4892. """yaml: logstash
  4893. Send job's console log to Logstash for processing and analyis of
  4894. your job data. Also stores test metrics from Junit.
  4895. Requires the Jenkins :jenkins-wiki:`Logstash Plugin <Logstash+Plugin>`.
  4896. :arg int max-lines: The maximum number of log lines to send to Logstash.
  4897. (default 1000)
  4898. :arg bool fail-build: Mark build as failed if this step fails.
  4899. (default false)
  4900. Minimal Example:
  4901. .. literalinclude:: /../../tests/publishers/fixtures/logstash-min.yaml
  4902. :language: yaml
  4903. Full Example:
  4904. .. literalinclude:: /../../tests/publishers/fixtures/logstash-full.yaml
  4905. :language: yaml
  4906. """
  4907. logstash = XML.SubElement(xml_parent,
  4908. 'jenkins.plugins.logstash.LogstashNotifier')
  4909. logstash.set('plugin', 'logstash')
  4910. mapping = [
  4911. ('max-lines', 'maxLines', 1000),
  4912. ('fail-build', 'failBuild', False),
  4913. ]
  4914. helpers.convert_mapping_to_xml(logstash, data, mapping, fail_required=True)
  4915. def image_gallery(registry, xml_parent, data):
  4916. """yaml: image-gallery
  4917. Produce an image gallery using Javascript library. Requires the Jenkins
  4918. :jenkins-wiki:`Image Gallery Plugin<Image+Gallery+Plugin>`.
  4919. :arg str gallery-type:
  4920. :gallery-type values:
  4921. * **archived-images-gallery** (default)
  4922. * **in-folder-comparative-gallery**
  4923. * **multiple-folder-comparative-gallery**
  4924. :arg str title: gallery title (optional)
  4925. :arg int image-width: width of the image (optional)
  4926. :arg bool unstable-if-no-artifacts: mark build as unstable
  4927. if no archived artifacts were found (default false)
  4928. :arg str includes: include pattern (valid for archived-images-gallery
  4929. gallery)
  4930. :arg str base-root-folder: base root dir (valid for comparative gallery)
  4931. :arg int image-inner-width: width of the image displayed in the inner
  4932. gallery popup (valid for comparative gallery, optional)
  4933. Example:
  4934. .. literalinclude:: /../../tests/publishers/fixtures/image-gallery001.yaml
  4935. """
  4936. def include_comparative_elements(gallery_parent_elem, gallery):
  4937. XML.SubElement(gallery_parent_elem, 'baseRootFolder').text = str(
  4938. gallery.get('base-root-folder', ''))
  4939. image_inner_width = gallery.get('image-inner-width', '')
  4940. if image_inner_width:
  4941. XML.SubElement(gallery_parent_elem, 'imageInnerWidth').text = str(
  4942. image_inner_width)
  4943. package_prefix = 'org.jenkinsci.plugins.imagegallery.'
  4944. builder = XML.SubElement(
  4945. xml_parent, package_prefix + 'ImageGalleryRecorder'
  4946. )
  4947. image_galleries = XML.SubElement(builder, 'imageGalleries')
  4948. galleries = {
  4949. 'archived-images-gallery': package_prefix + 'imagegallery.'
  4950. 'ArchivedImagesGallery',
  4951. 'in-folder-comparative-gallery': package_prefix + 'comparative.'
  4952. 'InFolderComparativeArchivedImagesGallery',
  4953. 'multiple-folder-comparative-gallery': package_prefix + 'comparative.'
  4954. 'MultipleFolderComparativeArchivedImagesGallery'
  4955. }
  4956. for gallery_def in data:
  4957. gallery_type = gallery_def.get('gallery-type',
  4958. 'archived-images-gallery')
  4959. if gallery_type not in galleries:
  4960. raise InvalidAttributeError('gallery-type', gallery_type,
  4961. galleries.keys())
  4962. gallery_config = XML.SubElement(
  4963. image_galleries, galleries[gallery_type])
  4964. XML.SubElement(gallery_config, 'title').text = str(
  4965. gallery_def.get('title', ''))
  4966. image_width = str(gallery_def.get('image-width', ''))
  4967. if image_width:
  4968. XML.SubElement(gallery_config, 'imageWidth').text = str(
  4969. image_width)
  4970. XML.SubElement(
  4971. gallery_config,
  4972. 'markBuildAsUnstableIfNoArchivesFound').text = str(gallery_def.get(
  4973. 'unstable-if-no-artifacts', False))
  4974. if gallery_type == 'archived-images-gallery':
  4975. XML.SubElement(gallery_config, 'includes').text = str(
  4976. gallery_def.get('includes', ''))
  4977. if gallery_type == 'in-folder-comparative-gallery':
  4978. include_comparative_elements(gallery_config, gallery_def)
  4979. if gallery_type == 'multiple-folder-comparative-gallery':
  4980. include_comparative_elements(gallery_config, gallery_def)
  4981. def naginator(registry, xml_parent, data):
  4982. """yaml: naginator
  4983. Automatically reschedule a build after a build failure
  4984. Requires the Jenkins :jenkins-wiki:`Naginator Plugin <Naginator+Plugin>`.
  4985. :arg bool rerun-unstable-builds: Rerun build for unstable builds as well
  4986. as failures (default false)
  4987. :arg bool rerun-matrix-part: Rerun build only for failed parts on the
  4988. matrix (>=1.12) (default false)
  4989. :arg int fixed-delay: Fixed delay in seconds before retrying build (cannot
  4990. be used with progressive-delay-increment or progressive-delay-maximum.
  4991. This is the default delay type. (default 0)
  4992. :arg int progressive-delay-increment: Progressive delay in seconds before
  4993. retrying build increment (cannot be used when fixed-delay is being
  4994. used) (default 0)
  4995. :arg int progressive-delay-maximum: Progressive delay in seconds before
  4996. retrying maximum delay (cannot be used when fixed-delay is being used)
  4997. (default 0)
  4998. :arg int max-failed-builds: Maximum number of successive failed builds
  4999. (default 0)
  5000. :arg str regular-expression: Only rerun build if regular expression is
  5001. found in output (default '')
  5002. Example:
  5003. .. literalinclude:: /../../tests/publishers/fixtures/naginator001.yaml
  5004. :language: yaml
  5005. """
  5006. naginator = XML.SubElement(
  5007. xml_parent,
  5008. 'com.chikli.hudson.plugin.naginator.NaginatorPublisher')
  5009. XML.SubElement(naginator, 'regexpForRerun').text = str(
  5010. data.get('regular-expression', ''))
  5011. XML.SubElement(naginator, 'checkRegexp').text = str(
  5012. 'regular-expression' in data).lower()
  5013. XML.SubElement(naginator, 'rerunIfUnstable').text = str(
  5014. data.get('rerun-unstable-builds', False)).lower()
  5015. XML.SubElement(naginator, 'rerunMatrixPart').text = str(
  5016. data.get('rerun-matrix-part', False)).lower()
  5017. progressive_delay = ('progressive-delay-increment' in data or
  5018. 'progressive-delay-maximum' in data)
  5019. if 'fixed-delay' in data and progressive_delay:
  5020. raise JenkinsJobsException("You cannot specify both fixed "
  5021. "and progressive delays")
  5022. if not progressive_delay:
  5023. delay = XML.SubElement(
  5024. naginator,
  5025. 'delay',
  5026. {'class': 'com.chikli.hudson.plugin.naginator.FixedDelay'})
  5027. XML.SubElement(delay, 'delay').text = str(
  5028. data.get('fixed-delay', '0'))
  5029. else:
  5030. delay = XML.SubElement(
  5031. naginator,
  5032. 'delay',
  5033. {'class': 'com.chikli.hudson.plugin.naginator.ProgressiveDelay'})
  5034. XML.SubElement(delay, 'increment').text = str(
  5035. data.get('progressive-delay-increment', '0'))
  5036. XML.SubElement(delay, 'max').text = str(
  5037. data.get('progressive-delay-maximum', '0'))
  5038. XML.SubElement(naginator, 'maxSchedule').text = str(
  5039. data.get('max-failed-builds', '0'))
  5040. def disable_failed_job(registry, xml_parent, data):
  5041. """yaml: disable-failed-job
  5042. Automatically disable failed jobs.
  5043. Requires the Jenkins :jenkins-wiki:`Disable Failed Job Plugin
  5044. <Disable+Failed+Job+Plugin>`.
  5045. :arg str when-to-disable: The condition to disable the job. (required)
  5046. Possible values are
  5047. * **Only Failure**
  5048. * **Failure and Unstable**
  5049. * **Unstable**
  5050. :arg int no-of-failures: Number of consecutive failures to disable the
  5051. job. (optional)
  5052. Example:
  5053. .. literalinclude::
  5054. /../../tests/publishers/fixtures/disable-failed-job001.yaml
  5055. :language: yaml
  5056. """
  5057. xml_element = XML.SubElement(xml_parent, 'disableFailedJob.'
  5058. 'disableFailedJob.DisableFailedJob',
  5059. {'plugin': 'disable-failed-job'})
  5060. valid_conditions = ['Only Failure',
  5061. 'Failure and Unstable',
  5062. 'Only Unstable']
  5063. mapping = [('when-to-disable', 'whenDisable', None, valid_conditions)]
  5064. helpers.convert_mapping_to_xml(
  5065. xml_element, data, mapping, fail_required=True)
  5066. if 'no-of-failures' in data:
  5067. mapping = [
  5068. ('no-of-failures', 'failureTimes', None),
  5069. ('', 'optionalBrockChecked', True)]
  5070. helpers.convert_mapping_to_xml(xml_element,
  5071. data, mapping, fail_required=True)
  5072. else:
  5073. XML.SubElement(xml_element, 'optionalBrockChecked').text = 'false'
  5074. def google_cloud_storage(registry, xml_parent, data):
  5075. """yaml: google-cloud-storage
  5076. Upload build artifacts to Google Cloud Storage. Requires the
  5077. Jenkins :jenkins-wiki:`Google Cloud Storage plugin
  5078. <Google+Cloud+Storage+Plugin>`.
  5079. Apart from the Google Cloud Storage Plugin itself, installation of Google
  5080. OAuth Credentials and addition of required credentials to Jenkins is
  5081. required.
  5082. :arg str credentials-id: The set of Google credentials registered with
  5083. the Jenkins Credential Manager for authenticating
  5084. with your project. (required)
  5085. :arg list uploads:
  5086. :uploads:
  5087. * **expiring-elements** (`dict`)
  5088. :params:
  5089. * **bucket-name** (`str`) bucket name to upload artifacts
  5090. (required)
  5091. * **days-to-retain** (`int`) days to keep artifacts
  5092. (required)
  5093. * **build-log** (`dict`)
  5094. :params:
  5095. * **log-name** (`str`) name of the file that the Jenkins
  5096. console log to be named (required)
  5097. * **storage-location** (`str`) bucket name to upload
  5098. artifacts (required)
  5099. * **share-publicly** (`bool`) whether to share uploaded
  5100. share uploaded artifacts with everyone (default false)
  5101. * **upload-for-failed-jobs** (`bool`) whether to upload
  5102. artifacts even if the build fails (default false)
  5103. * **show-inline** (`bool`) whether to show uploaded build
  5104. log inline in web browsers, rather than forcing it to be
  5105. downloaded (default true)
  5106. * **strip-prefix** (`str`) strip this prefix off the
  5107. file names (default not set)
  5108. * **classic** (`dict`)
  5109. :params:
  5110. * **file-pattern** (`str`) ant style globs to match the
  5111. files to upload (required)
  5112. * **storage-location** (`str`) bucket name to upload
  5113. artifacts (required)
  5114. * **share-publicly** (`bool`) whether to share uploaded
  5115. share uploaded artifacts with everyone (default false)
  5116. * **upload-for-failed-jobs** (`bool`) whether to upload
  5117. artifacts even if the build fails (default false)
  5118. * **show-inline** (`bool`) whether to show uploaded
  5119. artifacts inline in web browsers, rather than forcing
  5120. them to be downloaded (default false)
  5121. * **strip-prefix** (`str`) strip this prefix off the
  5122. file names (default not set)
  5123. Example:
  5124. .. literalinclude::
  5125. /../../tests/publishers/fixtures/google_cloud_storage001.yaml
  5126. :language: yaml
  5127. Full example:
  5128. .. literalinclude::
  5129. /../../tests/publishers/fixtures/google_cloud_storage002.yaml
  5130. :language: yaml
  5131. """
  5132. def expiring_elements(properties, upload_element, types):
  5133. # Handle expiring elements upload action
  5134. xml_element = XML.SubElement(upload_element, 'com.google.'
  5135. 'jenkins.plugins.storage.'
  5136. 'ExpiringBucketLifecycleManager')
  5137. mapping = [
  5138. ('bucket-name', 'bucketNameWithVars', None),
  5139. ('', 'sharedPublicly', False),
  5140. ('', 'forFailedJobs', False),
  5141. ('days-to-retain', 'bucketObjectTTL', None)]
  5142. helpers.convert_mapping_to_xml(
  5143. xml_element, properties, mapping, fail_required=True)
  5144. if types.count('expiring-elements') > 1:
  5145. XML.SubElement(xml_element, 'module',
  5146. {'reference': '../../com.google.jenkins.plugins.'
  5147. 'storage.ExpiringBucketLifecycleManager/module'})
  5148. else:
  5149. XML.SubElement(xml_element, 'module')
  5150. def build_log(properties, upload_element, types):
  5151. # Handle build log upload action
  5152. xml_element = XML.SubElement(upload_element, 'com.google.jenkins.'
  5153. 'plugins.storage.StdoutUpload')
  5154. mapping = [
  5155. ('storage-location', 'bucketNameWithVars', None),
  5156. ('share-publicly', 'sharedPublicly', False),
  5157. ('upload-for-failed-jobs', 'forFailedJobs', False),
  5158. ('show-inline', 'showInline', True),
  5159. ('strip-prefix', 'pathPrefix', ''),
  5160. ('log-name', 'logName', None)]
  5161. helpers.convert_mapping_to_xml(
  5162. xml_element, properties, mapping, fail_required=True)
  5163. if types.count('build-log') > 1:
  5164. XML.SubElement(xml_element, 'module',
  5165. {'reference': '../../com.google.jenkins.plugins.'
  5166. 'storage.StdoutUpload/module'})
  5167. else:
  5168. XML.SubElement(xml_element, 'module')
  5169. def classic(properties, upload_element, types):
  5170. # Handle classic upload action
  5171. xml_element = XML.SubElement(upload_element, 'com.google.jenkins.'
  5172. 'plugins.storage.ClassicUpload')
  5173. mapping = [
  5174. ('storage-location', 'bucketNameWithVars', None),
  5175. ('share-publicly', 'sharedPublicly', False),
  5176. ('upload-for-failed-jobs', 'forFailedJobs', False),
  5177. ('show-inline', 'showInline', False),
  5178. ('strip-prefix', 'pathPrefix', ''),
  5179. ('file-pattern', 'sourceGlobWithVars', None)]
  5180. helpers.convert_mapping_to_xml(
  5181. xml_element, properties, mapping, fail_required=True)
  5182. if types.count('classic') > 1:
  5183. XML.SubElement(xml_element, 'module',
  5184. {'reference': '../../com.google.jenkins.plugins.'
  5185. 'storage.ClassicUpload/module'})
  5186. else:
  5187. XML.SubElement(xml_element, 'module')
  5188. uploader = XML.SubElement(xml_parent,
  5189. 'com.google.jenkins.plugins.storage.'
  5190. 'GoogleCloudStorageUploader',
  5191. {'plugin': 'google-storage-plugin'})
  5192. mapping = [('credentials-id', 'credentialsId', None)]
  5193. helpers.convert_mapping_to_xml(uploader, data, mapping, fail_required=True)
  5194. valid_upload_types = ['expiring-elements',
  5195. 'build-log',
  5196. 'classic']
  5197. types = []
  5198. upload_element = XML.SubElement(uploader, 'uploads')
  5199. uploads = data['uploads']
  5200. for upload in uploads:
  5201. for upload_type, properties in upload.items():
  5202. types.append(upload_type)
  5203. if upload_type not in valid_upload_types:
  5204. raise InvalidAttributeError('uploads', upload_type,
  5205. valid_upload_types)
  5206. else:
  5207. locals()[upload_type.replace('-', '_')](
  5208. properties, upload_element, types)
  5209. def flowdock(registry, xml_parent, data):
  5210. """yaml: flowdock
  5211. This plugin publishes job build results to a Flowdock flow.
  5212. Requires the Jenkins :jenkins-wiki:`Flowdock Plugin
  5213. <Flowdock+Plugin>`.
  5214. :arg str token: API token for the targeted flow.
  5215. (required)
  5216. :arg str tags: Comma-separated list of tags to include in message
  5217. (default "")
  5218. :arg bool chat-notification: Send chat notification when build fails
  5219. (default true)
  5220. :arg bool notify-success: Send notification on build success
  5221. (default true)
  5222. :arg bool notify-failure: Send notification on build failure
  5223. (default true)
  5224. :arg bool notify-fixed: Send notification when build is fixed
  5225. (default true)
  5226. :arg bool notify-unstable: Send notification when build is unstable
  5227. (default false)
  5228. :arg bool notify-aborted: Send notification when build was aborted
  5229. (default false)
  5230. :arg bool notify-notbuilt: Send notification when build did not occur
  5231. (default false)
  5232. Example:
  5233. .. literalinclude:: /../../tests/publishers/fixtures/flowdock001.yaml
  5234. :language: yaml
  5235. Full example:
  5236. .. literalinclude:: /../../tests/publishers/fixtures/flowdock002.yaml
  5237. :language: yaml
  5238. """
  5239. def gen_notification_entry(data_item, default, text):
  5240. e = XML.SubElement(nm, 'entry')
  5241. mapping = [
  5242. ('', 'com.flowdock.jenkins.BuildResult', text),
  5243. (data_item, 'boolean', default)]
  5244. helpers.convert_mapping_to_xml(e, data, mapping, fail_required=True)
  5245. parent = XML.SubElement(xml_parent,
  5246. 'com.flowdock.jenkins.FlowdockNotifier')
  5247. mapping = [
  5248. ('token', 'flowToken', None),
  5249. ('tags', 'notificationTags', ''),
  5250. ('chat-notification', 'chatNotification', True),
  5251. ('notify-success', 'notifySuccess', True),
  5252. ('notify-failure', 'notifyFailure', True),
  5253. ('notify-fixed', 'notifyFixed', True),
  5254. ('notify-unstable', 'notifyUnstable', False),
  5255. ('notify-aborted', 'notifyAborted', False),
  5256. ('notify-notbuilt', 'notifyNotBuilt', False)]
  5257. helpers.convert_mapping_to_xml(parent, data, mapping, fail_required=True)
  5258. nm = XML.SubElement(parent, 'notifyMap')
  5259. # notification entries
  5260. gen_notification_entry('notify-success', True, 'SUCCESS')
  5261. gen_notification_entry('notify-failure', True, 'FAILURE')
  5262. gen_notification_entry('notify-fixed', True, 'FIXED')
  5263. gen_notification_entry('notify-unstable', False, 'UNSTABLE')
  5264. gen_notification_entry('notify-aborted', False, 'ABORTED')
  5265. gen_notification_entry('notify-notbuilt', False, 'NOT_BUILT')
  5266. def clamav(registry, xml_parent, data):
  5267. """yaml: clamav
  5268. Check files with ClamAV, an open source antivirus engine.
  5269. Requires the Jenkins :jenkins-wiki:`ClamAV Plugin <ClamAV+Plugin>`.
  5270. :arg str includes: Comma separated list of files that should be scanned.
  5271. Must be set for ClamAV to check for artifacts. (default '')
  5272. :arg str excludes: Comma separated list of files that should be ignored
  5273. (default '')
  5274. Full Example:
  5275. .. literalinclude:: /../../tests/publishers/fixtures/clamav-full.yaml
  5276. :language: yaml
  5277. Minimal Example:
  5278. .. literalinclude:: /../../tests/publishers/fixtures/clamav-minimal.yaml
  5279. :language: yaml
  5280. """
  5281. clamav = XML.SubElement(
  5282. xml_parent,
  5283. 'org.jenkinsci.plugins.clamav.ClamAvRecorder')
  5284. clamav.set('plugin', 'clamav')
  5285. mappings = [
  5286. ('includes', 'includes', ''),
  5287. ('excludes', 'excludes', ''),
  5288. ]
  5289. helpers.convert_mapping_to_xml(clamav, data, mappings, fail_required=True)
  5290. def testselector(registry, xml_parent, data):
  5291. """yaml: testselector
  5292. This plugin allows you to choose specific tests you want to run.
  5293. Requires the Jenkins :jenkins-wiki:`Tests Selector Plugin
  5294. <Tests+Selector+Plugin>`.
  5295. :arg str name: Environment variable in which selected tests are saved
  5296. (required)
  5297. :arg str description: Description
  5298. (default "")
  5299. :arg str properties-file: Contain all your tests
  5300. (required)
  5301. :arg str enable-field: Imply if the test is enabled or not
  5302. (default "")
  5303. :arg str groupby: Plugin will group the tests by
  5304. (default "")
  5305. :arg str field-sperator: Separate between the fields in the tests tree
  5306. (default "")
  5307. :arg str show-fields: Shown in the tests tree
  5308. (default "")
  5309. :arg str multiplicity-field: Number of times the test should run
  5310. (default "")
  5311. Example:
  5312. .. literalinclude:: /../../tests/publishers/fixtures/testselector001.yaml
  5313. :language: yaml
  5314. """
  5315. testselector = XML.SubElement(xml_parent, 'il.ac.technion.jenkins.plugins'
  5316. 'TestExecuter')
  5317. mapping = [
  5318. ('name', 'name', None),
  5319. ('description', 'description', ''),
  5320. ('properties-file', 'propertiesFilePath', None),
  5321. ('enable-field', 'enableField', ''),
  5322. ('groupby', 'groupBy', ''),
  5323. ('field-separator', 'fieldSeparator', ''),
  5324. ('show-fields', 'showFields', ''),
  5325. ('multiplicity-field', 'multiplicityField', ''),
  5326. ]
  5327. helpers.convert_mapping_to_xml(
  5328. testselector, data, mapping, fail_required=True)
  5329. def cloudformation(registry, xml_parent, data):
  5330. """yaml: cloudformation
  5331. Create cloudformation stacks before running a build and optionally
  5332. delete them at the end. Requires the Jenkins :jenkins-wiki:`AWS
  5333. Cloudformation Plugin <AWS+Cloudformation+Plugin>`.
  5334. :arg list create-stacks: List of stacks to create
  5335. :create-stacks attributes:
  5336. * **arg str name** - The name of the stack (Required)
  5337. * **arg str description** - Description of the stack (Optional)
  5338. * **arg str recipe** - The cloudformation recipe file (Required)
  5339. * **arg list parameters** - A list of key/value pairs, will be
  5340. joined together into a comma separated string (Optional)
  5341. * **arg int timeout** - Number of seconds to wait before giving up
  5342. creating a stack (default 0)
  5343. * **arg str access-key** - The Amazon API Access Key (Required)
  5344. * **arg str secret-key** - The Amazon API Secret Key (Required)
  5345. * **arg int sleep** - Number of seconds to wait before continuing
  5346. to the next step (default 0)
  5347. * **arg array region** - The region to run cloudformation in.
  5348. (Required)
  5349. :region values:
  5350. * **us-east-1**
  5351. * **us-west-1**
  5352. * **us-west-2**
  5353. * **eu-central-1**
  5354. * **eu-west-1**
  5355. * **ap-southeast-1**
  5356. * **ap-southeast-2**
  5357. * **ap-northeast-1**
  5358. * **sa-east-1**
  5359. :arg list delete-stacks: List of stacks to delete
  5360. :delete-stacks attributes:
  5361. * **arg list name** - The names of the stacks to delete (Required)
  5362. * **arg str access-key** - The Amazon API Access Key (Required)
  5363. * **arg str secret-key** - The Amazon API Secret Key (Required)
  5364. * **arg bool prefix** - If selected the tear down process will look
  5365. for the stack that Starts with the stack name with the oldest
  5366. creation date and will delete it. (default false)
  5367. * **arg array region** - The region to run cloudformation in.
  5368. (Required)
  5369. :region values:
  5370. * **us-east-1**
  5371. * **us-west-1**
  5372. * **us-west-2**
  5373. * **eu-central-1**
  5374. * **eu-west-1**
  5375. * **ap-southeast-1**
  5376. * **ap-southeast-2**
  5377. * **ap-northeast-1**
  5378. * **sa-east-1**
  5379. Example:
  5380. .. literalinclude:: /../../tests/publishers/fixtures/cloudformation.yaml
  5381. :language: yaml
  5382. """
  5383. region_dict = helpers.cloudformation_region_dict()
  5384. stacks = helpers.cloudformation_init(
  5385. xml_parent, data, 'CloudFormationPostBuildNotifier')
  5386. for stack in data.get('create-stacks', []):
  5387. helpers.cloudformation_stack(xml_parent, stack, 'PostBuildStackBean',
  5388. stacks, region_dict)
  5389. delete_stacks = helpers.cloudformation_init(
  5390. xml_parent, data, 'CloudFormationNotifier')
  5391. for delete_stack in data.get('delete-stacks', []):
  5392. helpers.cloudformation_stack(xml_parent, delete_stack,
  5393. 'SimpleStackBean', delete_stacks,
  5394. region_dict)
  5395. def whitesource(registry, xml_parent, data):
  5396. """yaml: whitesource
  5397. This plugin brings automatic open source management to Jenkins users.
  5398. Requires the Jenkins :jenkins-wiki:`Whitesource Plugin
  5399. <Whitesource+Plugin>`.
  5400. :arg str product-token: Product name or token to update (default '')
  5401. :arg str version: Product version (default '')
  5402. :arg str override-token: Override the api token from the global config
  5403. (default '')
  5404. :arg str project-token: Token uniquely identifying the project to update
  5405. (default '')
  5406. :arg list includes: list of libraries to include (default '[]')
  5407. :arg list excludes: list of libraries to exclude (default '[]')
  5408. :arg str policies: Whether to override the global settings. Valid values:
  5409. global, enable, disable (default 'global')
  5410. :arg str requester-email: Email of the WhiteSource user that requests to
  5411. update WhiteSource (>=1.5.1) (default '')
  5412. Full Example:
  5413. .. literalinclude:: /../../tests/publishers/fixtures/whitesource-full.yaml
  5414. :language: yaml
  5415. Minimal Example:
  5416. .. literalinclude::
  5417. /../../tests/publishers/fixtures/whitesource-minimal.yaml
  5418. :language: yaml
  5419. """
  5420. whitesource = XML.SubElement(xml_parent, 'org.whitesource.jenkins.'
  5421. 'WhiteSourcePublisher')
  5422. whitesource.set('plugin', 'whitesource')
  5423. policies = ['global', 'enable', 'disable']
  5424. mappings = [
  5425. ('policies', 'jobCheckPolicies', 'global', policies),
  5426. ('override-token', 'jobApiToken', ''),
  5427. ('product-token', 'product', ''),
  5428. ('version', 'productVersion', ''),
  5429. ('project-token', 'projectToken', ''),
  5430. ('requester-email', 'requesterEmail', ''),
  5431. ]
  5432. helpers.convert_mapping_to_xml(
  5433. whitesource, data, mappings, fail_required=True)
  5434. XML.SubElement(whitesource, 'libIncludes').text = ' '.join(
  5435. data.get('includes', []))
  5436. XML.SubElement(whitesource, 'libExcludes').text = ' '.join(
  5437. data.get('excludes', []))
  5438. XML.SubElement(whitesource, 'ignorePomModules').text = 'false'
  5439. def hipchat(registry, xml_parent, data):
  5440. """yaml: hipchat
  5441. Publisher that sends hipchat notifications on job events
  5442. Requires the Jenkins :jenkins-wiki:`Hipchat Plugin
  5443. <Hipchat+Plugin>` version >=1.9
  5444. Please see documentation for older plugin version
  5445. http://docs.openstack.org/infra/jenkins-job-builder/hipchat.html
  5446. :arg str token: This will override the default auth token (optional)
  5447. :arg list rooms: list of HipChat rooms to post messages to, overrides
  5448. global default (optional)
  5449. :arg bool notify-start: post messages about build start event
  5450. (default false)
  5451. :arg bool notify-success: post messages about successful build event
  5452. (default false)
  5453. :arg bool notify-aborted: post messages about aborted build event
  5454. (default false)
  5455. :arg bool notify-not-built: post messages about build set to NOT_BUILT.
  5456. This status code is used in a multi-stage build where a problem in
  5457. earlier stage prevented later stages from building. (default false)
  5458. :arg bool notify-unstable: post messages about unstable build event
  5459. (default false)
  5460. :arg bool notify-failure: post messages about build failure event
  5461. (default false)
  5462. :arg bool notify-back-to-normal: post messages about build being back to
  5463. normal after being unstable or failed (default false)
  5464. :arg str start-message: This will override the default start message
  5465. (optional)
  5466. :arg str complete-message: This will override the default complete message
  5467. (optional)
  5468. Example:
  5469. .. literalinclude:: /../../tests/publishers/fixtures/hipchat001.yaml
  5470. :language: yaml
  5471. """
  5472. hipchat = XML.SubElement(
  5473. xml_parent,
  5474. 'jenkins.plugins.hipchat.HipChatNotifier')
  5475. XML.SubElement(hipchat, 'token').text = str(
  5476. data.get('token', ''))
  5477. if 'rooms' in data:
  5478. XML.SubElement(hipchat, 'room').text = str(
  5479. ",".join(data['rooms']))
  5480. mapping = [
  5481. ('notify-start', 'startNotification', False),
  5482. ('notify-success', 'notifySuccess', False),
  5483. ('notify-aborted', 'notifyAborted', False),
  5484. ('notify-not-built', 'notifyNotBuilt', False),
  5485. ('notify-unstable', 'notifyUnstable', False),
  5486. ('notify-failure', 'notifyFailure', False),
  5487. ('notify-back-to-normal', 'notifyBackToNormal', False),
  5488. ('start-message', 'startJobMessage', None),
  5489. ('complete-message', 'completeJobMessage', None),
  5490. ]
  5491. helpers.convert_mapping_to_xml(hipchat, data, mapping, fail_required=False)
  5492. def slack(registry, xml_parent, data):
  5493. """yaml: slack
  5494. Publisher that sends slack notifications on job events.
  5495. Requires the Jenkins :jenkins-wiki:`Slack Plugin <Slack+Plugin>`
  5496. When using Slack Plugin version < 2.0, Slack Plugin itself requires a
  5497. publisher as well as properties please note that you have to create those
  5498. too. When using Slack Plugin version >= 2.0, you should only configure the
  5499. publisher.
  5500. For backward compatibility, the publisher needs to query version of the
  5501. Slack Plugin. Hence the ``query_plugins_info`` parameter shouldn't be set
  5502. to ``False`` in the ``jenkins`` section of the configuration file.
  5503. :arg str team-domain: Your team's domain at slack. (default '')
  5504. :arg str auth-token: The integration token to be used when sending
  5505. notifications. (default '')
  5506. :arg str auth-token-id: Allows credentials to be stored in Jenkins.
  5507. (default '')
  5508. :arg str build-server-url: Specify the URL for your server installation.
  5509. (default '/')
  5510. :arg str room: A comma separated list of rooms / channels to post the
  5511. notifications to. (default '')
  5512. :arg bool notify-start: Send notification when the job starts (>=2.0).
  5513. (default false)
  5514. :arg bool notify-success: Send notification on success (>=2.0).
  5515. (default false)
  5516. :arg bool notify-aborted: Send notification when job is aborted (>=2.0).
  5517. (default false)
  5518. :arg bool notify-not-built: Send notification when job set to NOT_BUILT
  5519. status (>=2.0). (default false)
  5520. :arg bool notify-unstable: Send notification when job becomes unstable
  5521. (>=2.0). (default false)
  5522. :arg bool notify-failure: Send notification when job fails for the first
  5523. time (previous build was a success) (>=2.0). (default false)
  5524. :arg bool notify-back-to-normal: Send notification when job is succeeding
  5525. again after being unstable or failed (>=2.0). (default false)
  5526. :arg bool notify-repeated-failure: Send notification when job fails
  5527. successively (previous build was also a failure) (>=2.0).
  5528. (default false)
  5529. :arg bool include-test-summary: Include the test summary (>=2.0).
  5530. (default false)
  5531. :arg str commit-info-choice: What commit information to include into
  5532. notification message, "NONE" includes nothing about commits, "AUTHORS"
  5533. includes commit list with authors only, and "AUTHORS_AND_TITLES"
  5534. includes commit list with authors and titles (>=2.0). (default "NONE")
  5535. :arg bool include-custom-message: Include a custom message into the
  5536. notification (>=2.0). (default false)
  5537. :arg str custom-message: Custom message to be included (>=2.0).
  5538. (default '')
  5539. :arg str auth-token-credential-id: The ID for the integration token from
  5540. the Credentials plugin to be used to send notifications to Slack.
  5541. (>=2.1) (default '')
  5542. :arg bool bot-user: This option indicates the token belongs to a bot user
  5543. in Slack. (>=2.2) (default False)
  5544. :arg str base-url: Your Slack compatible Base URL. ``bot-user`` is not
  5545. supported with Base URL. (>=2.2) (default '')
  5546. Example (version < 2.0):
  5547. .. literalinclude::
  5548. /../../tests/publishers/fixtures/slack001.yaml
  5549. :language: yaml
  5550. Minimal example (version >= 2.0):
  5551. .. literalinclude::
  5552. /../../tests/publishers/fixtures/slack003.yaml
  5553. :language: yaml
  5554. Full example (version >= 2.0):
  5555. .. literalinclude::
  5556. /../../tests/publishers/fixtures/slack004.yaml
  5557. :language: yaml
  5558. """
  5559. def _add_xml(elem, name, value=''):
  5560. if isinstance(value, bool):
  5561. value = str(value).lower()
  5562. XML.SubElement(elem, name).text = value
  5563. logger = logging.getLogger(__name__)
  5564. plugin_info = registry.get_plugin_info('Slack Notification Plugin')
  5565. # Note: Assume latest version of plugin is preferred config format
  5566. plugin_ver = pkg_resources.parse_version(
  5567. plugin_info.get('version', str(sys.maxsize)))
  5568. mapping = (
  5569. ('team-domain', 'teamDomain', ''),
  5570. ('auth-token', 'authToken', ''),
  5571. ('auth-token-id', 'authTokenCredentialId', ''),
  5572. ('build-server-url', 'buildServerUrl', '/'),
  5573. ('room', 'room', ''),
  5574. )
  5575. mapping_20 = (
  5576. ('notify-start', 'startNotification', False),
  5577. ('notify-success', 'notifySuccess', False),
  5578. ('notify-aborted', 'notifyAborted', False),
  5579. ('notify-not-built', 'notifyNotBuilt', False),
  5580. ('notify-unstable', 'notifyUnstable', False),
  5581. ('notify-failure', 'notifyFailure', False),
  5582. ('notify-back-to-normal', 'notifyBackToNormal', False),
  5583. ('notify-repeated-failure', 'notifyRepeatedFailure', False),
  5584. ('include-test-summary', 'includeTestSummary', False),
  5585. ('commit-info-choice', 'commitInfoChoice', 'NONE'),
  5586. ('include-custom-message', 'includeCustomMessage', False),
  5587. ('custom-message', 'customMessage', ''),
  5588. ('auth-token-credential-id', 'authTokenCredentialId', ''),
  5589. ('bot-user', 'botUser', False),
  5590. ('base-url', 'baseUrl', ''),
  5591. )
  5592. commit_info_choices = ['NONE', 'AUTHORS', 'AUTHORS_AND_TITLES']
  5593. slack = XML.SubElement(
  5594. xml_parent,
  5595. 'jenkins.plugins.slack.SlackNotifier',
  5596. )
  5597. if plugin_ver >= pkg_resources.parse_version("2.0"):
  5598. mapping = mapping + mapping_20
  5599. if plugin_ver < pkg_resources.parse_version("2.0"):
  5600. for yaml_name, _, default_value in mapping:
  5601. # All arguments that don't have a default value are mandatory for
  5602. # the plugin to work as intended.
  5603. if not data.get(yaml_name, default_value):
  5604. raise MissingAttributeError(yaml_name)
  5605. for yaml_name, _, _ in mapping_20:
  5606. if yaml_name in data:
  5607. logger.warning(
  5608. "'%s' is invalid with plugin version < 2.0, ignored",
  5609. yaml_name,
  5610. )
  5611. for yaml_name, xml_name, default_value in mapping:
  5612. value = data.get(yaml_name, default_value)
  5613. # 'commit-info-choice' is enumerated type
  5614. if (
  5615. yaml_name == 'commit-info-choice' and
  5616. value not in commit_info_choices):
  5617. raise InvalidAttributeError(
  5618. yaml_name, value, commit_info_choices,
  5619. )
  5620. # Ensure that custom-message is set when include-custom-message is set
  5621. # to true.
  5622. if (
  5623. yaml_name == 'include-custom-message' and
  5624. data is False and
  5625. not data.get('custom-message', '')):
  5626. raise MissingAttributeError('custom-message')
  5627. _add_xml(slack, xml_name, value)
  5628. def phabricator(registry, xml_parent, data):
  5629. """yaml: phabricator
  5630. Integrate with `Phabricator <http://phabricator.org/>`_
  5631. Requires the Jenkins :jenkins-wiki:`Phabricator Plugin
  5632. <Phabricator+Differential+Plugin>`.
  5633. :arg bool comment-on-success: Post a *comment* when the build
  5634. succeeds. (optional)
  5635. :arg bool uberalls-enabled: Integrate with uberalls. (optional)
  5636. :arg str comment-file: Include contents of given file if
  5637. commenting is enabled. (optional)
  5638. :arg int comment-size: Maximum comment character length. (optional)
  5639. :arg bool comment-with-console-link-on-failure: Post a *comment*
  5640. when the build fails. (optional)
  5641. Example:
  5642. .. literalinclude::
  5643. /../../tests/publishers/fixtures/phabricator001.yaml
  5644. :language: yaml
  5645. """
  5646. root = XML.SubElement(xml_parent,
  5647. 'com.uber.jenkins.phabricator.PhabricatorNotifier')
  5648. mapping = [
  5649. ('comment-on-success', 'commentOnSuccess', None),
  5650. ('uberalls-enabled', 'uberallsEnabled', None),
  5651. ('comment-file', 'commentFile', None),
  5652. ('comment-size', 'commentSize', None),
  5653. ('comment-with-console-link-on-failure',
  5654. 'commentWithConsoleLinkOnFailure', None),
  5655. ]
  5656. helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
  5657. def jms_messaging(registry, xml_parent, data):
  5658. """yaml: jms-messaging
  5659. The JMS Messaging Plugin provides the following functionality:
  5660. - A build trigger to submit jenkins jobs upon receipt
  5661. of a matching message.
  5662. - A builder that may be used to submit a message to the topic
  5663. upon the completion of a job
  5664. - A post-build action that may be used to submit a message to the topic
  5665. upon the completion of a job
  5666. JMS Messaging provider types supported:
  5667. - ActiveMQ
  5668. - FedMsg
  5669. Requires the Jenkins :jenkins-wiki:`JMS Messaging Plugin
  5670. Pipeline Plugin <JMS+Messaging+Plugin>`.
  5671. :arg str override-topic: If you need to override the default topic.
  5672. (default '')
  5673. :arg str provider-name: Name of message provider setup in the
  5674. global config. (default '')
  5675. :arg str msg-type: A message type
  5676. (default 'CodeQualityChecksDone')
  5677. :arg str msg-props: Message header to publish. (default '')
  5678. :arg str msg-content: Message body to publish. (default '')
  5679. Full Example:
  5680. .. literalinclude::
  5681. ../../tests/publishers/fixtures/jms-messaging-full.yaml
  5682. :language: yaml
  5683. Minimal Example:
  5684. .. literalinclude::
  5685. ../../tests/publishers/fixtures/jms-messaging-minimal.yaml
  5686. :language: yaml
  5687. """
  5688. helpers.jms_messaging_common(xml_parent, 'com.redhat.jenkins.plugins.ci.'
  5689. 'CIMessageNotifier', data)
  5690. def openshift_build_canceller(registry, xml_parent, data):
  5691. """yaml: openshift-build-canceller
  5692. This action is intended to provide cleanup for a Jenkins job which failed
  5693. because a build is hung (instead of terminating with a failure code);
  5694. this step will allow you to perform the equivalent of a oc cancel-build
  5695. for the provided build config; any builds under that build config which
  5696. are not previously terminated (either successfully or unsuccessfully)
  5697. or cancelled will be cancelled.
  5698. Requires the Jenkins :jenkins-wiki:`OpenShift
  5699. Pipeline Plugin <OpenShift+Pipeline+Plugin>`.
  5700. :arg str api-url: this would be the value you specify if you leverage the
  5701. --server option on the OpenShift `oc` command.
  5702. (default '\https://openshift.default.svc.cluster.local')
  5703. :arg str bld-cfg: The value here should be whatever was the output
  5704. form `oc project` when you created the BuildConfig you
  5705. want to run a Build on (default 'frontend')
  5706. :arg str namespace: If you run `oc get bc` for the project listed in
  5707. "namespace", that is the value you want to put here. (default 'test')
  5708. :arg str auth-token: The value here is what you supply with the --token
  5709. option when invoking the OpenShift `oc` command. (default '')
  5710. :arg bool verbose: This flag is the toggle for
  5711. turning on or off detailed logging in this plug-in. (default false)
  5712. Full Example:
  5713. .. literalinclude::
  5714. ../../tests/publishers/fixtures/openshift-build-canceller001.yaml
  5715. :language: yaml
  5716. Minimal Example:
  5717. .. literalinclude::
  5718. ../../tests/publishers/fixtures/openshift-build-canceller002.yaml
  5719. :language: yaml
  5720. """
  5721. osb = XML.SubElement(xml_parent,
  5722. 'com.openshift.jenkins.plugins.pipeline.'
  5723. 'OpenShiftBuildCanceller')
  5724. mapping = [
  5725. # option, xml name, default value
  5726. ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
  5727. ("bld-cfg", 'bldCfg', 'frontend'),
  5728. ("namespace", 'namespace', 'test'),
  5729. ("auth-token", 'authToken', ''),
  5730. ("verbose", 'verbose', False),
  5731. ]
  5732. helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
  5733. def openshift_deploy_canceller(registry, xml_parent, data):
  5734. """yaml: openshift-deploy-canceller
  5735. This action is intended to provide cleanup for any OpenShift deployments
  5736. left running when the Job completes; this step will allow you to perform
  5737. the equivalent of a oc deploy --cancel for the provided deployment config.
  5738. Requires the Jenkins :jenkins-wiki:`OpenShift
  5739. Pipeline Plugin <OpenShift+Pipeline+Plugin>`.
  5740. :arg str api-url: this would be the value you specify if you leverage the
  5741. --server option on the OpenShift `oc` command.
  5742. (default '\https://openshift.default.svc.cluster.local')
  5743. :arg str dep-cfg: The value here should be whatever was the output
  5744. form `oc project` when you created the BuildConfig you want to run a
  5745. Build on (default frontend)
  5746. :arg str namespace: If you run `oc get bc` for the project listed in
  5747. "namespace", that is the value you want to put here. (default 'test')
  5748. :arg str auth-token: The value here is what you supply with the --token
  5749. option when invoking the OpenShift `oc` command. (default '')
  5750. :arg bool verbose: This flag is the toggle for
  5751. turning on or off detailed logging in this plug-in. (default false)
  5752. Full Example:
  5753. .. literalinclude::
  5754. ../../tests/publishers/fixtures/openshift-deploy-canceller001.yaml
  5755. :language: yaml
  5756. Minimal Example:
  5757. .. literalinclude::
  5758. ../../tests/publishers/fixtures/openshift-deploy-canceller002.yaml
  5759. :language: yaml
  5760. """
  5761. osb = XML.SubElement(xml_parent,
  5762. 'com.openshift.jenkins.plugins.pipeline.'
  5763. 'OpenShiftDeployCanceller')
  5764. mapping = [
  5765. # option, xml name, default value
  5766. ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
  5767. ("dep-cfg", 'depCfg', 'frontend'),
  5768. ("namespace", 'namespace', 'test'),
  5769. ("auth-token", 'authToken', ''),
  5770. ("verbose", 'verbose', False),
  5771. ]
  5772. helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
  5773. def github_pull_request_merge(registry, xml_parent, data):
  5774. """yaml: github-pull-request-merge
  5775. This action merges the pull request that triggered the build (see the
  5776. github pull request trigger)
  5777. Requires the Jenkins :jenkins-wiki:`GitHub pull request builder plugin
  5778. <GitHub+pull+request+builder+plugin>`.
  5779. :arg bool only-admins-merge: if `true` only administrators can merge the
  5780. pull request, (default false)
  5781. :arg bool disallow-own-code: if `true` will allow merging your own pull
  5782. requests, in opposite to needing someone else to trigger the merge.
  5783. (default false)
  5784. :arg str merge-comment: Comment to set on the merge commit (default '')
  5785. :arg bool fail-on-non-merge: fail the job if the merge was unsuccessful
  5786. (default false)
  5787. :arg bool delete-on-merge: Delete the branch of the pull request on
  5788. successful merge (default false)
  5789. Full Example:
  5790. .. literalinclude::
  5791. ../../tests/publishers/fixtures/github-pull-request-merge001.yaml
  5792. :language: yaml
  5793. Minimal Example:
  5794. .. literalinclude::
  5795. ../../tests/publishers/fixtures/github-pull-request-merge002.yaml
  5796. :language: yaml
  5797. """
  5798. osb = XML.SubElement(xml_parent,
  5799. 'org.jenkinsci.plugins.ghprb.GhprbPullRequestMerge')
  5800. mapping = [
  5801. # option, xml name, default value
  5802. ("only-admins-merge", 'onlyAdminsMerge', 'false'),
  5803. ("disallow-own-code", 'disallowOwnCode', 'false'),
  5804. ("merge-comment", 'mergeComment', ''),
  5805. ("fail-on-non-merge", 'failOnNonMerge', 'false'),
  5806. ("delete-on-merge", 'deleteOnMerge', 'false'),
  5807. ]
  5808. helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
  5809. def chuck_norris(registry, xml_parent, data):
  5810. """yaml: chuck-norris
  5811. Displays a picture of Chuck Norris (instead of Jenkins the butler) and a
  5812. random Chuck Norris 'The Programmer' fact on each build page.
  5813. Requires the Jenkins :jenkins-wiki:`ChuckNorris Plugin
  5814. <ChuckNorris+Plugin>`.
  5815. Example:
  5816. .. literalinclude:: /../../tests/publishers/fixtures/chuck-norris.yaml
  5817. :language: yaml
  5818. """
  5819. chuck = XML.SubElement(xml_parent,
  5820. 'hudson.plugins.chucknorris.CordellWalkerRecorder')
  5821. return XML.SubElement(chuck, "factGenerator")
  5822. def tasks(registry, xml_parent, data):
  5823. """yaml: tasks
  5824. Scans the workspace files for open tasks and generates a trend report.
  5825. Requires the Jenkins
  5826. :jenkins-wiki:`Task Scanner Plugin <Task+Scanner+Plugin>`.
  5827. :arg list files-to-scan: Fileset includes setting that specifies the
  5828. workspace files to scan for tasks, such as ``**/*.java``. Basedir of
  5829. the fileset is the workspace root. (default '``**/*.java``')
  5830. :arg list files-to-exclude: Fileset excludes setting that specifies the
  5831. workspace files to exclude scanning for tasks, such as library source
  5832. files. Basedir of the fileset is the workspace root. (default '')
  5833. :arg list tasks-tags-high: Tags identifiers for high priority that should
  5834. be looked for in the workspace files. Only alphanumerical characters
  5835. are allowed as tags as these strings are pasted into a regular
  5836. expression. (default '')
  5837. :arg list tasks-tags-normal: Tags identifiers for normal priority that
  5838. should be looked for in the workspace files. Only alphanumerical
  5839. characters are allowed as tags as these strings are pasted into a
  5840. regular expression. (default '')
  5841. :arg list tasks-tags-low: Tags identifiers for low priority that should be
  5842. looked for in the workspace files. Only alphanumerical characters are
  5843. allowed as tags as these strings are pasted into a regular expression.
  5844. (default '')
  5845. :arg bool ignore-case: Ignore the case of the the tag identifiers. (default
  5846. false)
  5847. :arg bool regular-expression: Treat the tag identifiers as regular
  5848. expression. Note that the regular expression must contain two capturing
  5849. groups, the first one is interpreted as tag name, the second one as
  5850. message. An example of such a regular expression would be
  5851. ``^.*(TODO(?:[0-9]*))(.*)$``. (default false)
  5852. :arg bool run-always: By default, this plug-in runs only for stable or
  5853. unstable builds, but not for failed builds. If this plug-in should run
  5854. even for failed builds then activate this check box. (default false)
  5855. :arg bool detect-module: Determines if Ant or Maven modules should be
  5856. detected for all files that contain warnings. Activating this option
  5857. may increase your build time since the detector scans the whole
  5858. workspace for ``build.xml`` or ``pom.xml`` files in order to assign the
  5859. correct module names. (default false)
  5860. :arg int health-thresholds-100: Configure the upper thresholds for the
  5861. build health. If left empty then no health report is created. If the
  5862. actual number of warnings is between the provided thresholds then the
  5863. build health is interpolated. (default '')
  5864. :arg str health-thresholds-0: Configure the lower thresholds for the build
  5865. health. If left empty then no health report is created. If the actual
  5866. number of warnings is between the provided thresholds then the build
  5867. health is interpolated. (default '')
  5868. :arg str health-priorities: Determines which warning priorities should be
  5869. considered when evaluating the build health. Can be ``high`` (only
  5870. priority high), ``normal`` (priorities high and normal) or ``low`` (all
  5871. priorities). (default 'low')
  5872. :arg dict status-thresholds: Configure the build status and health. If the
  5873. number of total or new warnings is greater than one of these thresholds
  5874. then a build is considered as unstable or failed, respectively. I.e., a
  5875. value of 0 means that the build status is changed if there is at least
  5876. one warning found. Leave this field empty if the state of the build
  5877. should not depend on the number of warnings. Note that for new
  5878. warnings, you need to enable the next option
  5879. (``compute-new-warnings``).
  5880. :status-thresholds:
  5881. * **unstable-total-all** (`str`): Total number for all priorities,
  5882. unstable threshold (default '')
  5883. * **unstable-total-high** (`str`): Total number for high priority,
  5884. unstable threshold (default '')
  5885. * **unstable-total-normal** (`str`): Total number for normal
  5886. priority, unstable threshold (default '')
  5887. * **unstable-total-low** (`str`): Total number for low priority,
  5888. unstable threshold (default '')
  5889. * **failed-total-all** (`str`): Total number for all priorities,
  5890. failure threshold (default '')
  5891. * **failed-total-high** (`str`): Total number for high priority,
  5892. failure threshold (default '')
  5893. * **failed-total-normal** (`str`): Total number for normal
  5894. priority, failure threshold (default '')
  5895. * **failed-total-low** (`str`): Total number for low priority,
  5896. failure threshold (default '')
  5897. * **unstable-new-all** (`str`): New number for all priorities,
  5898. unstable threshold (default '')
  5899. * **unstable-new-high** (`str`): New number for high priority,
  5900. unstable threshold (default '')
  5901. * **unstable-new-normal** (`str`): New number for normal priority,
  5902. unstable threshold (default '')
  5903. * **unstable-new-low** (`str`): New number for low priority,
  5904. unstable threshold (default '')
  5905. * **failed-new-all** (`str`): New number for all priorities,
  5906. failure threshold (default '')
  5907. * **failed-new-high** (`str`): New number for high priority,
  5908. failure threshold (default '')
  5909. * **failed-new-normal** (`str`): New number for normal priority,
  5910. failure threshold (default '')
  5911. * **failed-new-low** (`str`): New number for low priority, failure
  5912. threshold (default '')
  5913. :arg bool compute-new-warnings: Compute new warnings (based on the last
  5914. successful build unless another reference build is chosen below).
  5915. (default false)
  5916. :arg bool use-delta: If set the number of new warnings is computed by
  5917. subtracting the total number of warnings of the reference build from
  5918. the total number of warnings of the current build. This may lead to
  5919. wrong results if you have both fixed and new warnings in a build. If
  5920. unset the number of new warnings is computed by a more sophisticated
  5921. algorithm: instead of using totals an asymmetric set difference of the
  5922. warnings in the current build and the warnings in the reference build
  5923. is used. This will find all new warnings even if the number of total
  5924. warnings has decreased. Note that sometimes false positives will be
  5925. reported due to minor changes in a warning (e.g. refactoring of
  5926. variables or method names). It is recommended to uncheck this option in
  5927. order to get the most accurate results for new warnings. Depends on
  5928. ``compute-new-warnings`` option. (default false)
  5929. :arg bool use-prev-build-as-ref: If set the number of new warnings will
  5930. always be computed based on the previous build, even if that build is
  5931. unstable (due to a violated warning threshold). Otherwise the last
  5932. build that did not violate any given threshold will be used as
  5933. reference. It is recommended to uncheck this option if the plug-in
  5934. should ensure that all new warnings will be finally fixed in subsequent
  5935. builds. Depends on ``compute-new-warnings`` option. (default false)
  5936. :arg bool only-use-stable-as-ref: Use the last stable build as the
  5937. reference to compute the number of new warnings against. This allows
  5938. you to ignore interim unstable builds for which the number of warnings
  5939. decreased. Note that the last stable build is evaluated only by
  5940. inspecting the unit test failures. The static analysis results are not
  5941. considered. Depends on ``compute-new-warnings`` option. (default false)
  5942. :arg str default-encoding: Default encoding when parsing or showing files.
  5943. Leave this field empty to use the default encoding of the platform.
  5944. (default '')
  5945. Minimal Example:
  5946. .. literalinclude:: /../../tests/publishers/fixtures/tasks-minimal.yaml
  5947. :language: yaml
  5948. Full Example:
  5949. .. literalinclude:: /../../tests/publishers/fixtures/tasks-full.yaml
  5950. :language: yaml
  5951. """
  5952. root = XML.SubElement(xml_parent,
  5953. 'hudson.plugins.tasks.TasksPublisher')
  5954. root.set('plugin', 'tasks')
  5955. if 'files-to-scan' in data:
  5956. XML.SubElement(root, 'pattern').text = str(
  5957. ",".join(data['files-to-scan']))
  5958. if 'files-to-exclude' in data:
  5959. XML.SubElement(root, 'excludePattern').text = str(
  5960. ",".join(data['files-to-exclude']))
  5961. for prio in ['high', 'normal', 'low']:
  5962. if 'tasks-tags-' + prio in data:
  5963. XML.SubElement(root, prio).text = str(
  5964. ",".join(data['tasks-tags-' + prio]))
  5965. # on the UI, we can see compute-new-warnings but we need the opposite (XML)
  5966. if 'compute-new-warnings' in data and data['compute-new-warnings']:
  5967. XML.SubElement(root, 'dontComputeNew').text = "false"
  5968. else:
  5969. XML.SubElement(root, 'dontComputeNew').text = "true"
  5970. # Two parameters we cannot modify from the UI
  5971. XML.SubElement(root, 'pluginName').text = "[TASKS] "
  5972. XML.SubElement(root, 'doNotResolveRelativePaths').text = "false"
  5973. mappings = [
  5974. ('ignore-case', 'ignoreCase', False),
  5975. ('regular-expression', 'asRegexp', False),
  5976. ('run-always', 'canRunOnFailed', False),
  5977. ('detect-module', 'shouldDetectModules', False),
  5978. ('health-thresholds-100', 'healthy', ''),
  5979. ('health-thresholds-0', 'unHealthy', ''),
  5980. ('health-priorities', 'thresholdLimit', 'low'),
  5981. ('use-delta', 'useDeltaValues', False),
  5982. ('use-prev-build-as-ref', 'usePreviousBuildAsReference', False),
  5983. ('only-use-stable-as-ref', 'useStableBuildAsReference', False),
  5984. ('default-encoding', 'defaultEncoding', '')
  5985. ]
  5986. helpers.convert_mapping_to_xml(root, data, mappings, fail_required=True)
  5987. thrsh_xml = XML.SubElement(root, 'thresholds')
  5988. thrsh_xml.set('plugin', 'analysis-core')
  5989. thrsh_data = data.get('status-thresholds', {})
  5990. thrsh_mappings = [
  5991. ('unstable-total-all', 'unstableTotalAll', ''),
  5992. ('unstable-total-high', 'unstableTotalHigh', ''),
  5993. ('unstable-total-normal', 'unstableTotalNormal', ''),
  5994. ('unstable-total-low', 'unstableTotalLow', ''),
  5995. ('unstable-new-all', 'unstableNewAll', ''),
  5996. ('unstable-new-high', 'unstableNewHigh', ''),
  5997. ('unstable-new-normal', 'unstableNewNormal', ''),
  5998. ('unstable-new-low', 'unstableNewLow', ''),
  5999. ('failed-total-all', 'failedTotalAll', ''),
  6000. ('failed-total-high', 'failedTotalHigh', ''),
  6001. ('failed-total-normal', 'failedTotalNormal', ''),
  6002. ('failed-total-low', 'failedTotalLow', ''),
  6003. ('failed-new-all', 'failedNewAll', ''),
  6004. ('failed-new-high', 'failedNewHigh', ''),
  6005. ('failed-new-normal', 'failedNewNormal', ''),
  6006. ('failed-new-low', 'failedNewLow', '')
  6007. ]
  6008. helpers.convert_mapping_to_xml(
  6009. thrsh_xml, thrsh_data, thrsh_mappings, fail_required=True)
  6010. class Publishers(jenkins_jobs.modules.base.Base):
  6011. sequence = 70
  6012. component_type = 'publisher'
  6013. component_list_type = 'publishers'
  6014. def gen_xml(self, xml_parent, data):
  6015. publishers = XML.SubElement(xml_parent, 'publishers')
  6016. for action in data.get('publishers', []):
  6017. self.registry.dispatch('publisher', publishers, action)