日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

jenkins构建python代码_Jenkins之使用Pyinstaller构建Python应用程序

發(fā)布時(shí)間:2023/12/10 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jenkins构建python代码_Jenkins之使用Pyinstaller构建Python应用程序 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 極簡(jiǎn)概述

Jenkins是一個(gè)獨(dú)立的開源自動(dòng)化服務(wù)器,可用于自動(dòng)執(zhí)行與構(gòu)建,測(cè)試,交付或部署軟件相關(guān)的各種任務(wù),。

Jenkins可以通過本機(jī)系統(tǒng)軟件包,Docker安裝,甚至可以由安裝了Java Runtime Environment(JRE)的任何機(jī)器獨(dú)立運(yùn)行。

2. Jenkins配置

安裝Jenkins很簡(jiǎn)單,首先安裝Java8,然后再安裝Jenkins,這里使用Jenkins的2.173版本。包的話,直接去官網(wǎng)下載吧。

2.1 安裝JDK

(1) 解壓JDK

[root@jenkins ~]# tar zxvf jdk-8u171-linux-x64.tar.gz

[root@jenkins ~]# mv jdk1.8.0_171/ /usr/local/java

(2)添加環(huán)境變量

[root@jenkins ~]# vim /etc/profile # 寫入如下內(nèi)容

export JAVA_HOME=/usr/local/java

export PATH=$PATH:$MAVEN_HOME/bin:$JAVA_HOME/bin

export JRE_HOME=$JAVA_HOME/jre

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

(3) 立即生效

[root@jenkins ~]# source /etc/profile

[root@jenkins ~]# java -version

java version "1.8.0_171"

Java(TM) SE Runtime Environment (build 1.8.0_171-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

2.2 安裝Jenkins

(1) 直接用jre跑

[root@jenkins ~]# java -jar jenkins.war --httpPort=8080

(2) 訪問Web

http://localhost:8080

(3) 跟著配置

注意:如果這一步出現(xiàn):Problem accessing /setupWizard/createAdminUser. Reason:,那么直接使用admin登陸。

(4) 安裝插件Open Blue Ocean

Blue Ocean為開發(fā)人員提供了更具樂趣的Jenkins使用方式,它是從基礎(chǔ)開始構(gòu)建的,實(shí)現(xiàn)了一種全新的、現(xiàn)代風(fēng)格的用戶界面,有助于任何規(guī)模的團(tuán)隊(duì)實(shí)現(xiàn)持續(xù)交付。它以Jenkins插件的方式安裝,并集成于Jenkins的流水線中。

注意:版本2.165可能出現(xiàn)安裝失敗。解決方法未知。

3. 安裝Docker

(1)安裝依賴

[root@jenkins ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

[root@jenkins ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

[root@jenkins ~]# yum install docker-ce docker-ce-cli containerd.io

[root@jenkins ~]# sudo systemctl start docker

[root@jenkins ~]# docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

1b930d010525: Pull complete

Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e

Status: Downloaded newer image for hello-world:latest

Hello from Docker!

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

(amd64)

3. The Docker daemon created a new container from that image which runs the

executable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent it

to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

https://hub.docker.com/

For more examples and ideas, visit:

https://docs.docker.com/get-started/

4. 使用PyInstaller構(gòu)建Python應(yīng)用程序

必須條件:

GitHub賬號(hào)

4.1 Fork 一個(gè)庫

該存儲(chǔ)庫中包含一個(gè)簡(jiǎn)單的Python應(yīng)用程序,它是一個(gè)命令行工具“add2vals”,它輸出兩個(gè)值的相加。如果至少有一個(gè)值是字符串,則“add2vals”將這兩個(gè)值視為字符串,而是將值連接起來。

鏈接為:https://github.com/jenkins-docs/simple-python-pyinstaller-app

4.2 克隆項(xiàng)目

# 自己創(chuàng)建GitHub這個(gè)目錄

[root@jenkins GitHub]# pwd

/root/GitHub

[root@jenkins GitHub]# git clone https://github.com/liuhedong135/simple-python-pyinstaller-app.git

Cloning into 'simple-python-pyinstaller-app'...

remote: Enumerating objects: 36, done.

remote: Total 36 (delta 0), reused 0 (delta 0), pack-reused 36

Unpacking objects: 100% (36/36), done.

[root@jenkins GitHub]# tree simple-python-pyinstaller-app/

simple-python-pyinstaller-app/

├── jenkins

│?? └── Jenkinsfile

├── README.md

└── sources

├── add2vals.py

├── calc.py

└── test_calc.py

2 directories, 5 files

4.3 在Jenkins創(chuàng)建管道項(xiàng)目

[root@jenkins GitHub]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

Generating public/private rsa key pair.

Created directory '/root/.ssh'.

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:Fgo8vZIPd5ITBmPVx0nB5m8Ihc0wxZUTOjeTJZv7qrA root@jenkins

The key's randomart image is:

+---[RSA 2048]----+

| +...o@+++o. |

| o + o.@.o* |

| + + .=o B. |

| = =...o + |

| + B S. o. |

| = = . o. |

| . . . . |

| o . |

| E ... |

+----[SHA256]-----+

[root@jenkins GitHub]# cat ~/.ssh/id_rsa

-----BEGIN RSA PRIVATE KEY-----

MIIEogIBAAKCAQEA4RrL+SbBJgMWmZJTvnZoMQ9L1pfQ1qPDDG+rcM/nCIng8ai+

WI6adg894jIP20pYvDLojTHx/zKMcOAOhUuileclui5coViYnFUwLpr+V6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An5zAZPcr3FZcjXzwQWibjYl+3i4WQZcfubC0P/r

7E3zsjXOEpzDK3EfFIP6pQKBgDVRLufcGMo4ddZ2HGRuYnPGYH50Nbw9Z5p8DN52

e2IaC4WovDkiYSPW44ZAVdN63Cs76sW0DHgzcFOSWZfd4FfFS5FZKXcVFQ8684j8

+JSH8xOAst9FLMO6rXj+O5Jz2rqTdCv532krBiM1kezCAlqaBNE3Ib1z2S4ZrLN4

Je85AoGAU5L+ZEjGB/9ayk47j5UOaquFfvRd+0v0sgdRnU0QxPSYy/vuRvTiaADS

Cp4//7+z+fixHgbtZQYSYdGK4c6YSj6bcVhlvOfSG1oe/O/J42PzDVljl6DCxMT9

mJc31CK32iFpQmXXPV8lyWcPuVr6qHmg1gvd4eNqp0N9L3Z9x6Y=

-----END RSA PRIVATE KEY-----

4.4 為初始管道創(chuàng)建Jenkinsfile

[root@jenkins simple-python-pyinstaller-app]# pwd

/root/GitHub/simple-python-pyinstaller-app

[root@jenkins simple-python-pyinstaller-app]# vim Jenkinsfile

# 寫入如下內(nèi)容

pipeline {

agent none

stages {

stage('Build') {

agent {

docker {

image 'python:2-alpine'

}

}

steps {

sh 'python -m py_compile sources/add2vals.py sources/calc.py'

}

}

}

}

[root@jenkins simple-python-pyinstaller-app]# git config --global user.email "liuhedong135@163/com"

[root@jenkins simple-python-pyinstaller-app]# git config --global user.name "liuhedong"

[root@jenkins simple-python-pyinstaller-app]# git add .

[root@jenkins simple-python-pyinstaller-app]# git commit -m "Add initial Jenkinsfile"

[master 6966a7d] Add initial Jenkinsfile

1 file changed, 15 insertions(+)

create mode 100644 Jenkinsfile

4.5 測(cè)試階段

[root@jenkins simple-python-pyinstaller-app]# pwd

/root/GitHub/simple-python-pyinstaller-app

[root@jenkins simple-python-pyinstaller-app]# vim Jenkinsfile

# 添加如下內(nèi)容

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'

}

}

}

[root@jenkins simple-python-pyinstaller-app]# cat Jenkinsfile

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'

}

}

}

}

}

[root@jenkins simple-python-pyinstaller-app]# git stage .

[root@jenkins simple-python-pyinstaller-app]# git commit -m "Add Test stage"

[master 342b643] Add Test stage

1 file changed, 16 insertions(+)

重新進(jìn)入Blue Ocean

4.6 交付階段

[root@jenkins simple-python-pyinstaller-app]# pwd

/root/GitHub/simple-python-pyinstaller-app

[root@jenkins simple-python-pyinstaller-app]# vim Jenkinsfile

# 寫入如下內(nèi)容

stage('Deliver') {

agent {

docker {

image 'cdrx/pyinstaller-linux:python2'

}

}

steps {

sh 'pyinstaller --onefile sources/add2vals.py'

}

post {

success {

archiveArtifacts 'dist/add2vals'

}

}

}

# 最終為如下內(nèi)容

[root@jenkins simple-python-pyinstaller-app]# cat Jenkinsfile

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'

}

}

}

}

}

[root@jenkins simple-python-pyinstaller-app]# git stage .

[root@jenkins simple-python-pyinstaller-app]# git commit -m "Add Deliver stage"

[master 19c0c48] Add Deliver stage

1 file changed, 15 insertions(+)

重新進(jìn)入Blue Ocean

最后點(diǎn)擊下載,并傳入到linux,

[root@jenkins ~]# ls -lh

total 3.4M

-rw-r--r-- 1 root root 3.4M Apr 21 10:54 add2vals

drwxr-xr-x 3 root root 43 Apr 22 09:32 GitHub

[root@jenkins ~]# chmod +x add2vals

[root@jenkins ~]# ./add2vals

You entered 0 value/s.

Usage: 'add2vals X Y' where X and Y are individual values.

If add2vals is not in your path, usage is './add2vals X Y'.

If unbundled, usage is 'python add2vals.py X Y'.

[root@jenkins ~]# ./add2vals 1 1

The result is 2

最后我們就成功的將應(yīng)用打包,并在linux上運(yùn)行,這個(gè)應(yīng)用是一個(gè)簡(jiǎn)單的計(jì)算。

總結(jié)

以上是生活随笔為你收集整理的jenkins构建python代码_Jenkins之使用Pyinstaller构建Python应用程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。