Continuous Integration advanced part of Jenkins Pipeline git pull

Series catalog

PipeLine pulls a remote git repository

Speaking in front Freestyle task, we can see through freestyle job in providing a graphical interface to configure git pull is very convenient, in fact, use PipeLine is not complicated. In this section we show you how to pull in PipeLine task take git repository code.

node{
    stage("check out"){
         git  credentialsId: '3c210def-c000-4e2a-9b2d-838986a6b172', url: 'https://github.com/mrtylerzhou/gitShow.git'
    }
}

The above code is very simple, by using git keywords, configuration credentialsId, and urlafter Jenkins can pull remote git repository code .Url well understood, is the address of the remote repository. Here is more difficult to understand credentialsIdwhat it is, how to set it? In fact, is also very simple, speaking in front of freestyle task when we talked about how git add to add a user name and password in jenkins, here credentialsIdis the id contains the user name and password of the user information that we created (the id is automatically generated jenkins ) here by the id, Jenkins will be able to find the user name and password.

Create a user name and password

To create a user name and password is not very complex, we find in the main panel Jenkins left navigation panel Credentials, click to enter, you can see one of the following panel

img

Here on the left Credentialsfollowing a Systemwe click, then the panel central location in the following figure

img

We click on the link, then the left will add a Credentialsbutton

img

Click there will be a user interface can be set names and passwords

img

As illustrated, Kindthe default, add a user name and password. Then add the user name and password, id can manually input this time, if left blank Jenkins automatically generates a .Description a brief description, when the user name and password are many easily distinguish .

After the success we want to see id add this record, click on the right panel screwdriver wrench icon, you can see the id we copy this id in the PipeLinecredentialsId

Add a ssh key

Username and password easy to leak, practical work often use ssh landing approach, here on how to generate ssh key, how to add a public key will not go in a remote warehouse, unfamiliar shoes can refer to previous chapters or official help documentation and on the Internet the search for relevant material. here at how to add a private key to ssh in Jenkins, Jenkins use ssh to connect to a remote warehouse.

Add the private key is similar to the above add user name and password, just add a user name and password Kindoption to use the default option, where Kindthe drop-down look, choose SSH username with private key, your user name is the git user account name, private keycheck Enter directlyto our private key of the machine Tim copied to the box inside.

Note that ssh and http address is not the same, we must pay attention.

The code location specified pulled

Jenkins is the default installation directory Jenkins pulled the project Workspace+项目名directory below, often due to some reasons we might want to change this behavior, the project pulled a custom directory, this time you can use dirthe function, and then to be executed the code is written in dirthe function block. following sample code

node{
    stage("check out"){
        dir("projdir"){
            git  credentialsId: '3c210def-c000-4e2a-9b2d-838986a6b172', url: 'https://github.com/mrtylerzhou/gitShow.git'
        }
         
    }
}

After the above statement is executed, you can see the code jenkins will pull Workspace+项目名+projdirin the catalog, of course, you can specify an absolute path.

Guess you like

Origin www.cnblogs.com/tylerzhou/p/11444579.html