Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get Jenkins to execute pipeline scripts on GitHub

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to let Jenkins execute the pipeline script on GitHub". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to let Jenkins execute the pipeline script on GitHub".

Environmental information

To quickly build a Jenkins environment, I use Docker here. For more information on deploying Jenkins, please see "Jenkins pipelining (pipeline): from deployment to experience". Today's actual combat needs to be carried out in the following environments:

Operating system: Ubuntu 18.04.2 LT

Docker:19.03.1

Jenkins: 2.176.3 (running with Docker environment)

Upload pipeline script files to GitHub

This actual combat uses my own GitHub account, and the code repository is: https://github.com/zq2599/blog_demos

Write a pipeline script file for testing and upload it to GitHub, as shown below. The file address is: https://github.com/zq2599/blog_demos/blob/master/blueocean/helloworld/Jenkinsfile

The relative path of the Jenkinsfile file in the code repository is blueocean/helloworld, as shown below:

GitHub Open license

In order for Jenkins to download pipelien scripts from GitHub smoothly, you need to open the license on GitHub in a specific way:

After logging in to GitHub, click Settings in the account menu in the upper right corner, as shown below:

Click the "Developer settings" button in the red box below:

Click the "Personal access tokens" button in the red box below:

The next step is to create an authorized token page. To select the open authorization feature, as shown in the figure below, the Jenkins in the two red boxes will be used, and must be checked:

After the setting is completed, click the green Generate token button at the bottom to generate a string, which is the authorized token. Copy it down and use it later. At this point, the setting on GitHub is complete, and then set the pipeline task on Jenkins.

Jenkins sets pipelined tasks

Now let's create a pipelined task on Jenkins that downloads the pipeline script you just uploaded from GitHub

Click Blue Ocean on the left menu of Jenkins to go to the Blue Ocean page. The Blue Ocean page is more suitable for pipeline management and configuration than the original Jenkins settings page:

Click the create pipeline button in the red box below:

The page you enter is shown in the following figure. This is the page that sets the pipeline. You can complete the creation of the pipeline by setting it according to the serial number:

Since the Jenkinsfile file is not in the first-level directory of the GitHub repository, it is not scanned by Jenkins, so we need to manually specify the location of the Jenkinsfile file and click the red box button in the following figure to return to the task list:

Click the task you just created in the task list, as shown in the red box below:

Click the icon in the red box below to jump to the Jenkins settings page of the task:

As shown in the following figure, find the Build Configuration setting, and enter blueocean/helloworld/Jenkinsfile in the red box below, which is the relative location of the file you just uploaded in the repository:

Click the Save button at the bottom to save the configuration:

At this point, Jenkins will automatically start a task to scan the GitHub repository. If the configuration is correct, the task will be executed successfully:

After configuration, go back to the Blue Ocean page again, click on the task, and follow the red box below to run the task:

After the task starts, click the activity button in the red box below to view the execution of the task:

Click any of the execution records in the above figure to view the details, as shown in the figure below. The third execution shows that the pipeline script was successfully obtained from GitHub and executed successfully:

Modify the pipeline source code and execute it again

Next, verify whether the modified pipeline script can take effect immediately:

Modify the contents of the Jenkinsfile file and submit them to GitHub. As shown in the red box below, the contents printed on the console have been modified:

Start the task on the Blue Ocean page again, which shows that both the Jenkinsfile update and the task execution are successful:

Thank you for reading, the above is the content of "how to let Jenkins execute the pipeline script on GitHub". After the study of this article, I believe you have a deeper understanding of how to let Jenkins execute the pipeline script on GitHub, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report