Change jenkins pipeline to use github instead of gitlab

后端 未结 2 893
清酒与你
清酒与你 2021-01-12 19:57

I have a set of automated tests that are ran in a jenkins pipeline, testcode is located in gitlab. The section where I pull code from gitlab looks like this:

相关标签:
2条回答
  • 2021-01-12 20:39

    After some intense googling I found the answer, which proved to be a lot easier then I thought:

    Apparently a personal access token can be used like a password, as far as jenkins is concerned atleast. I added new credentials to the credential manager, chose type 'username and password', put in a non existing username ('user') and put the personal access token in the password field.

    This way I could choose the credentials from the dropdown like I did before, and the project was cloned without issues

    0 讨论(0)
  • 2021-01-12 20:53

    You can configure Jenkins instance with Github with the help of SSH key

    You Just have to create SSH public and private keys and past public key in

    Github > Settings > SSH/GPC key > Add public key Make sure you will not add any space and new line

    Save and exit from Github

    Now go to Jenkins * Start to configure your project, or Go to credentials > System > Global credentials > Add credentials a page will open

    • In Kind drop-down select SSH Username with private key
    • Check private key radio button and then press Add key button, a textarea will open paste your private key in that textarea, Make sure you copy the private key and while pasting not adding any space in it. Make sure you select the whole key, Begin and End text of key also.

    • Now Save and while Configuring Project Source Code Management tab, you will find credentials and a drop-down, select the new configured key from that dropdown jenkinsSSH.

    • Make sure your clone your Github repo using SSH not HTTPS

    and build the application. this will work

    for more reference watch this video tutorial https://www.youtube.com/watch?v=mGXGIOpKAos&list=PLhW3qG5bs-L_ZCOA4zNPSoGbnVQ-rp_dG&index=9

    [Update]

    To clone git repository using Personal Access Token, you can use following format

    https://user:token@github.exampleco.com/org/repo.git like

    git clone https://user:token@github.exampleco.com/org/repo.git

    there is one more question same as this, and he provided one solution, might help you

    Git Clone in Jenkins with Personal Access Token idles forever

    please have a look

    0 讨论(0)
提交回复
热议问题