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 url
after Jenkins can pull remote git repository code .Url well understood, is the address of the remote repository. Here is more difficult to understand credentialsId
what 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 credentialsId
is 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
Here on the left Credentials
following a System
we click, then the panel central location in the following figure
We click on the link, then the left will add a Credentials
button
Click there will be a user interface can be set names and passwords
As illustrated, Kind
the 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 Kind
option to use the default option, where Kind
the drop-down look, choose SSH username with private key
, your user name is the git user account name, private key
check Enter directly
to 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 dir
the function, and then to be executed the code is written in dir
the 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+项目名+projdir
in the catalog, of course, you can specify an absolute path.