Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Nyob zoo, Hab!

Hnub no kuv xav qhia ib txoj hauv kev siv Active Xaiv Plugin ua haujlwm hauv Jenkins qhov sib koom ua ke tshaj plaws thiab siv tau zoo.

Taw qhia

Xws li cov ntawv luv li DevOps tsis yog ib yam tshiab rau IT zej zog. Rau ntau tus neeg, cov kab lus "ua DevOps" yog txuam nrog qee yam khawm khawv koob, thaum nias, daim ntawv thov code cia li hloov mus rau hauv daim ntawv thov siv thiab sim (txhua yam yog qhov nyuaj dua, tab sis peb yog abstracting los ntawm tag nrho cov txheej txheem).

Yog li, peb tau txais kev txiav txim los ua kom lub pob khawv koob zoo li no kom cov thawj coj tuaj yeem xa daim ntawv thov nrog ib nias. Muaj ntau hom kev siv ntawm txoj haujlwm no: los ntawm kev sau ntawv bot rau ib qho ntawm cov neeg xa xov tam sim mus rau kev tsim ib daim ntawv thov cais. Txawm li cas los xij, txhua yam no muaj tib lub hom phiaj - ua kom pib tsim thiab xa tawm daim ntawv thov kom pom tseeb thiab yooj yim li sai tau.

Hauv peb qhov xwm txheej peb yuav siv Jenkins.


Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Hom phiaj

Tsim ib txoj haujlwm yooj yim Jenkins uas yuav pib tsim thiab (lossis) kev xa tawm ntawm kev xaiv microservice ntawm qee yam version.

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Cov ntaub ntawv nkag

Peb muaj ntau lub chaw cia khoom uas muaj cov cai ntawm ntau yam microservices.

Txhais cov parameter

Cov kev txwv hauv qab no yuav tsum tau txais raws li kev nkag mus rau peb txoj haujlwm:

  1. Qhov URL ntawm qhov chaw cia khoom nrog microservice code uas peb xav tsim thiab xa tawm thaum ua haujlwm.
  2. ID ntawm kev cog lus los ntawm kev tsim yuav tshwm sim.

AS yog

Txoj hauv kev yooj yim tshaj plaws los ua kom tiav txoj haujlwm no yog los tsim ob qhov tsis sib xws ntawm String.

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Nyob rau hauv cov ntaub ntawv no, tus neeg siv yuav tsum tau manually nkag mus rau hauv txoj kev mus rau lub repository thiab cov lus cog tseg id, uas, koj pom, yog tsis yooj yim kiag li.

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

AS IB

Tam sim no cia sim ua lwm hom kev ntsuas los txiav txim siab tag nrho nws qhov zoo.
Cia peb tsim thawj qhov kev ntsuas nrog hom Kev Xaiv Parameter, qhov thib ob - Cov Kev Xaiv Ua Haujlwm Reactive Reference Parameter. Nyob rau hauv parameter nrog rau hom xaiv, peb yuav manually ntxiv nyob rau hauv cov kev xaiv teb cov npe ntawm repositories qhov twg cov cai ntawm peb microservices yog khaws cia.

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Yog tias cov neeg tuaj saib nyiam cov kab lus no, tom qab ntawd hauv tsab xov xwm tom ntej kuv yuav piav qhia txog cov txheej txheem ntawm kev teeb tsa cov haujlwm hauv Jenkins, siv cov lus piav qhia los ntawm cov lej (Kev teeb tsa raws li cov cai), piv txwv li. peb yuav tsis xav tau manually sau cov npe repository thiab tsim tsis, txhua yam yuav tshwm sim tau txais (peb cov cai yuav tau txais ib daim ntawv teev cov repositories los ntawm SCM thiab tsim ib tug parameter nrog rau daim ntawv no).

Qhov tseem ceeb ntawm qhov thib ob parameter yuav tsum tau sau dynamically, nyob ntawm seb tus nqi ntawm cov thawj parameter yuav siv sij hawm (test1 los yog test2), vim hais tias txhua repository muaj nws tus kheej daim ntawv teev cov commits.

Active Choices Reactive Reference Parameter muaj cov nram qab no teb rau hauv:

  1. lub npe - parameter npe.
  2. Tsab ntawv - code uas yuav raug ua txhua lub sij hawm tus nqi ntawm parameter los ntawm Referenced parameter teb yog hloov (nyob rau hauv peb cov ntaub ntawv, thaum peb xaiv ntawm test1 thiab test2).
  3. Hauj lwm - piav qhia luv luv ntawm parameter.
  4. Hom kev xaiv - hom khoom xa rov qab los ntawm tsab ntawv (hauv peb rooj plaub peb yuav rov qab html code).
  5. Siv parameter - lub npe ntawm qhov ntsuas, thaum tus nqi ntawm qhov hloov pauv, cov lej los ntawm Tshooj Lus yuav raug tua.

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Cia peb mus ncaj qha mus sau qhov tseem ceeb tshaj plaws hauv qhov ntsuas no. Peb muaj ob hom kev siv los xaiv los ntawm: siv Groovy Tsab Ntawv los yog Scriptler Script.
Peb xaiv thawj zaug, txij li Scriptler tsuas yog ib lub plugin uas txuag cov ntawv koj tau sau yav dhau los thiab tso cai rau koj siv lawv hauv lwm yam haujlwm yam tsis tau luam tawm dua.

Groovy code kom tau txais tag nrho cov lus cog tseg los ntawm qhov chaw khaws cia xaiv:

AUTH = "Π»ΠΎΠ³ΠΈΠ½ ΠΈ ΠΏΠ°Ρ€ΠΎΠ»ΡŒ Π² Base64"                           
GIT_URL = "url до вашСй SCM (https://bitbucket.org/)"                       
PROJECT_NAME = "имя ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π½ΠΎΠΉ области, Π³Π΄Π΅ находятся Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ"

def htmlBuild() {
    html = """
            <html>
            <head>
            <meta charset="windows-1251">
            <style type="text/css">
            div.grayTable {
            text-align: left;
            border-collapse: collapse;
            }
            .divTable.grayTable .divTableCell, .divTable.grayTable .divTableHead {
            padding: 0px 3px;
            }
            .divTable.grayTable .divTableBody .divTableCell {
            font-size: 13px;
            }
            </style>
            </head>
            <body>
        """

    def commitOptions = ""
    getCommitsForMicroservice(MICROSERVICE_NAME).each {
        commitOptions += "<option style='font-style: italic' value='COMMIT=${it.getKey()}'>${it}</option>"
    }
    html += """<p style="display: inline-block;">
        <select id="commit_id" size="1" name="value">
            ${commitOptions}
        </select></p></div>"""

    html += """
            </div>
            </div>
            </div>
            </body>
            </html>
         """
    return html
}

def getCommitsForMicroservice(microserviceRepo) {
    def commits = [:]
    def endpoint = GIT_URL + "/rest/api/1.0/projects/${PROJECT_NAME}/repos/${microserviceRepo}/commits"
    def conn = new URL(endpoint).openConnection()
    conn.setRequestProperty("Authorization", "Basic ${AUTH}")
    def response = new groovy.json.JsonSlurper().parseText(conn.content.text)
    response.values.each {
        commits.put(it.displayId, it.message)
    }
    return commits
}

return htmlBuild()

Yog tsis nkag mus rau hauv cov ntsiab lus, cov lej no tau txais lub npe microservice (MICROSERVICE_NAME) raws li kev nkag thiab xa ib daim ntawv thov mus rau Bitbucket (txoj kev getCommitsForMicroservice) siv nws API, thiab tau txais tus ID thiab cog lus ntawm txhua qhov kev cog lus rau kev pabcuam microservice.
Raws li tau hais ua ntej, cov cai no yuav tsum rov qab html uas yuav tshwm sim ntawm nplooj ntawv Tsim nrog Parameters hauv Jenkins, yog li peb qhwv tag nrho cov txiaj ntsig tau txais los ntawm Bitbucket hauv ib daim ntawv teev npe thiab ntxiv rau xaiv.

Tom qab ua tiav tag nrho cov kauj ruam, peb yuav tsum tau txais nplooj ntawv zoo nkauj no Tsim nrog Parameters.

Yog tias koj xaiv test1 microservice:

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Yog tias koj xaiv test2 microservice:

Tsim cov kev tsis sib haum xeeb hauv txoj haujlwm Jenkins, lossis yuav ua li cas ua rau koj txoj haujlwm zoo rau cov neeg siv

Pom zoo tias nws yuav yooj yim dua rau tus neeg siv los cuam tshuam nrog koj txoj haujlwm hauv txoj haujlwm no dua li luam url txhua lub sijhawm thiab nrhiav qhov yuav tsum tau ua id.

PS Kab lus no muab piv txwv yooj yim heev, uas tej zaum yuav tsis yog siv rau hauv daim ntawv no, vim tias cov rooj sib tham muaj ntau qhov sib txawv, tab sis lub hom phiaj ntawm tsab xov xwm no yog los qhia tias cov cuab yeej ua haujlwm li cas, tsis yog muab kev daws teeb meem ua haujlwm.

PSS Raws li kuv tau sau ua ntej, yog tias tsab xov xwm no muaj txiaj ntsig, tom ntej no yuav hais txog dynamic configuration ntawm Jenkins ua hauj lwm ntawm code.

Tau qhov twg los: www.hab.com

Ntxiv ib saib