A Concise introduction to Jenkins (ii)--using Jenkins to complete the build, test, deployment of the Python program

Source: Internet
Author: User

You may not have figured out what Jenkins can do.

This section uses Jenkins to complete the build, test, and deployment of the Python program, giving you an intuitive understanding of what Jenkins can do.

The contents of this section are rewritten from https://jenkins.io/doc/tutorials/build-a-python-app-with-pyinstaller/.

1. Fork,clone the sample repo on GitHub

The sample repo on GitHub contains the Python program's BUiD, Test, depolyment code, so we need to fork this repo first, then clone it to our local machine.

About this Python program, it is also very simple, is to calculate the two parameters and. The code in repo contains the program ontology (compute and), as well as all the necessary code and tools such as Unittest,build (generated by Pyinstaller).

1.1 Login to GitHub, if not, go to register a

1.2 Fork on GitHubsimple-python-pyinstaller-app, 如果不知道如何fork,请参考 Fork A Repo

1.3 Clone This repo to the local machine by:

Open the Linux command line

cd/home/<your-username>/github/

git clone Https://github.com/YOUR-GITHUB-ACCOUNT-NAME/simple-python-pyinstaller-app

(Remember to replace <your-username> and your-github-account-name for your real path name and username)

2. Create Pipline project in Jenkins

Pipline translation is the meaning of "pipeline", in fact, this you put the whole build, Test, deployment process into a pipeline, your code in the inside flow, through different stages, it is good to understand.

2.1 After you sign in to Jenkins, click New Item in the upper left corner of the initial interface

2.2 Name Pipline project as you specified, for example Simple-python-pyinstaller-app

2.3 Pull down, select Pipline, click OK

2.4 Select Pipline tab and then pull down to see Pipline section:

Definition select Pipline scirpt from SCM, this option allows Jenkins to be obtained from the source Control Management (SCM), the SCM is actually your clone to the local machine repo

SCM Choose Git

Repository URL Fill in the path of your clone to the local machine repo:/home/github/simple-python-pyinstaller-app

Click Save

3. Create the Jenkinsfile in Pipline

Jenkinsfile actually prescribes what is done in Jenkins's pipline process.

Create the Jenkinsfile file under your/home/github/simple-python-pyinstaller-app path and fill in the following code:

Pipeline {Agent None Stages {stage ('Build'{agent {docker {image'Python:2-alpine'}} steps {sh'python-m py_compile sources/add2vals.py sources/calc.py'}} stage ('Test'{agent {docker {image'qnib/pytest'}} steps {sh'py.test--verbose--junit-xml test-reports/results.xml sources/test_calc.py'} post {always {JUnit'Test-reports/results.xml'}}} stage ('Deliver'{agent {docker {image'Cdrx/pyinstaller-linux:python2'}} steps {sh'Pyinstaller--onefile sources/add2vals.py'} post {success {archiveartifacts'dist/add2vals'                 }            }        }    }}

Save the file, and then run the following command to commit the changes:

git Add.

Git commit-m "Create the Jenkinsfile"

4. Run the Pipline with blue ocean and observe

Go back to the Jenkins initial page, log in, select Blue Ocean from the list on the left and click "Run"

On this page, you can see how the Pipline is running

Click on each step, you can see the specific running situation, in which program, error messages, and so on.

If you want to see your pipline (what we call activity), then you need to click Blue Ocean, select your project, and then click the activity

If you need to run the resulting executable file, you can choose the activity you ran this time pipline. Locate the executable file add2vals, download and then execute:

chmod +x Add2vals

./add2vals 1 2

In this section we have a rough idea of what Jenkins can do for us: build,test,deliver, the work flow of Jenkins, and how Jenkinsfile rules out how pipline works. In the next section we will use the convenient features of blue ocean so that we only need to manipulate the Web page, specify the contents of build, Test, deliver, and automatically generate the Jenkinsfile file for us.

A Concise introduction to Jenkins (ii)--using Jenkins to complete the build, test, deployment of the Python program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.