Jenkins pipeline + Gitlab mark

Environment: 

Jenkins: 

OS: CentOS 7

Jenkins Version: 2.150.1

Gitlab(CE):

OS: CentOS 7

Gitlab Version: 11.9.4

1. install Jenkins and Gitlab 

2. Create a user in Gitlab(named jenkins, set a password)

3. On Jenkins server, run command as follow:

    a) git config --global user.name "jenkins"

    b) git config --global user.email "[email protected]"

    c) ssh-keygen -t rsa -C "[email protected]"

4. Copy .ssh/id_rsa.pub SSH key to gitlab website (User: jenkins, User Settings -> SSH Keys)

5. Go to Jenkins Website and create a credentials for gitlab (username: jenkins, password: your set, gitlab url: your gitlab server), get the credentialsId

6. Create a new pipeline as follow example Script

node {
   stage('Preparation') {
      git url: 'http://gitlab.example.com/jenkins/test-jenkins.git',
          credentialsId: 'fa17e92f-e72f-415d-8325-5471024af638',     #Step 5
          branch: 'master'
   }
   stage('hello_python') {
      sh 'python jenkins-python/hello.py'
   }
   stage('hello_shell') {
      sh 'sh jenkins-shell/hello.sh'
   }
}

PS:

1. Git repos downloaded in Jenkins server

[root@jenkins-server new_pipeline]# pwd
/root/.jenkins/workspace/new_pipeline
[root@jenkins-server new_pipeline]# tree
.
├── jenkins-python
│   └── hello.py
├── jenkins-shell
│   └── hello.sh
└── README.md

2 directories, 3 files
 

2. On gitlab

Gitlab url: http://gitlab.example.com/jenkins/test-jenkins.git

├── jenkins-python
│   └── hello.py
├── jenkins-shell
│   └── hello.sh
└── README.md

猜你喜欢

转载自blog.csdn.net/fc66ds1001/article/details/89023617