job's done使用存储库中的.jobs_done.yaml文件在jenkins上创建连续集成作业。
jobs-done10的Python项目详细描述
工作完成
关于
job's done是一个深受travis启发的工具
在存储库根目录中配置一个.jobs\u done.yaml
文件来创建和触发连续集成作业。
示例一个.jobs\u done.yaml
文件:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"
考虑到此文件位于repositorymyproject
的根目录中,并被推送到branchfeat-71
,这将生成两个jenkins作业:
myproject-feat-71-win64
myproject-feat-71-linux64
命令行
可以在命令行中执行已完成的作业。从存储库的文件夹执行:
$ jobs_done jenkins --username USER https://example.com/jenkins
这将创建/更新现有作业。
服务器
已完成的作业包括一个flask
jobs done10.server中的端点,可以使用Docker进行部署
此端点是为从BitBucket服务器实例的Webhook接收推送事件而定制的。一个没有任何 json数据将返回已安装的版本,有助于检查已安装的版本和端点是否正确。
配置
配置是通过一个.env
文件(cortesy ofpython dotenv)
在该存储库的根目录中,包含以下变量:
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=587
构建
克隆存储库并签出标记:
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>
创建Docker图像:
$ docker build . --tag jobsdone:<VERSION> --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=<VERSION>
运行服务器
$ docker run --publish 5000:5000 jobsdone:<VERSION>
你好世界
这是一个作业已完成文件的示例,以及您对其内容的期望。
build_batch_commands:-"echoMESSAGE:Hello,world!"description_regex:"MESSAGE\\:(.*)"
将此文件添加到连接到我们的ci系统的存储库中,将创建一个作业,在执行时运行 windows批处理命令,稍后会捕获回显的消息并将其设置为生成说明。
测试
这是一个带有测试的简单应用程序示例:
build_batch_commands:-"pytest--junitxml=pytest_results.xml"junit_patterns:-"pytest_results.xml"
此作业在存储库中运行pytest并将测试结果输出到文件。我们还将作业配置为查找 存档,并在生成结束时将测试结果呈现给我们。
多平台
与上面相同的应用程序,但现在运行在多个平台上。
platform-win64:build_batch_commands:-"pytest--junitxml=pytest_results-{platform}.xml"platform-redhat64:build_shell_commands:-"pytest--junitxml=pytest_results-{platform}.xml"junit_patterns:-"pytest_results.*.xml"matrix:platform:-"win64"-"redhat64"
在这里,我们添加一个矩阵部分来定义此作业的变体。在这种情况下,我们有平台变量,
有两个可能值,win64
和redhat64
将为矩阵中的每个可能组合创建一个作业(在这种情况下只有两个作业)。
由于我们不能在Linux中运行批处理命令,我们添加了另一个构建器部分,build\u shell\u commands
。使用一些标志
在定义节之前,我们可以选择每个工作中可用的选项。
矩阵中的值也可以用作变量,在这种情况下,{platform}
将被使用的平台替换
在那个工作中(win64
或redhat64
)。
分支模式
分支模式用于筛选哪些分支将生成作业。这个正则表达式列表 (使用python语法),确保分支仅在至少一个 表达式与分支的名称匹配。
下面是一个仅过滤master
和功能分支的示例:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"0
如果文件中未定义此部分,则所有分支都将生成作业。
作业矩阵
如上例所示,作业矩阵可用于创建作业的多个变体。 为该矩阵中的每个条目组合创建一个作业。
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"1
在这种情况下,将生成4个作业:
app-win64
app-linux64
cases-win64
cases-linux64
注意,您可以使用所需的任何变量,job's done不知道模式或
平台意味着什么。
有一个exclude
子句可用于从矩阵中删除特定条目:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"2
这将从Windows中排除所有案例作业。
字符串替换
作业矩阵中定义的变量可用于替换作业文件中的字符串。
除矩阵变量外,还有一些特殊的字符串模板可用于任何作业:
名称
-存储库的名称分支
-正在构建分支
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"3
请注意,我们使用python的格式语法,因此如果需要实际的{
或}
请使用双大括号:{
,}
条件标志
作业矩阵中定义的变量也可用于控制作业文件中的某些内容。 这里的一个常见示例是使用不同的windows(bash)和linux(shell)构建器。
这是通过在yaml文件的部分中添加前缀来完成的,前缀中包含使用该前缀所需的变量名和值:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"4
矩阵变量也可以定义别名,在使用此类标志时有助于减少重复。 要添加别名,只需使用逗号分隔矩阵值的其他名称:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"5
除此之外,您还可以使用始终可用的特殊变量branch
并指向您的分支:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"6
条件值可以使用python regex语法以获得额外的灵活性:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"7
开发
创建虚拟环境并以开发模式安装:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"8
运行测试:
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"9
部署到PYPI
已完成的作业可以部署到pypi。打开更新变更日志的PR,并在其通过后,将标记推送到存储库; travis将看到标记并自动将包发布到pypi。
所有选项
其他存储库
要在此作业中签出的其他存储库。
默认情况下,包含此.jobs完成文件的存储库。
使用与git相同的选项
$ jobs_done jenkins --username USER https://example.com/jenkins
0
身份验证令牌
远程触发生成所需的作业身份验证令牌。
$ jobs_done jenkins --username USER https://example.com/jenkins
1
boosttest_模式
查找测试结果的boosttest文件模式列表。
需要xunit插件
$ jobs_done jenkins --username USER https://example.com/jenkins
2
分支模式
用于匹配分支名称的正则表达式列表。 只有与其中一个匹配的分支才能创建 乔布斯.
matrix:platform:-"win64"-"redhat64"platform-win64:build_batch_commands:-|python -m venv .env3 || goto eofcall .env3\Scripts\activate || goto eofpytest --junitxml=tests-{platform}.xml platform-redhat64:build_shell_commands:-|python3 -m venv .env3source .env3/bin/activatepytest --junitxml=tests-{platform}.xml junit_patterns:-"tests.*.xml"0
生成批处理命令
< W列表>用于生成作业的windows批处理命令。 如果在任何命令之后errorcode不是0,则生成失败。$ jobs_done jenkins --username USER https://example.com/jenkins
4
构建shell命令
用于生成作业的shell命令列表。 如果在任何命令之后errorcode不是0,则生成失败。
$ jobs_done jenkins --username USER https://example.com/jenkins
5
生成python命令
用于生成作业的python命令列表。
需要python插件
$ jobs_done jenkins --username USER https://example.com/jenkins
6
控制台颜色
支持ANSI转义序列(包括颜色)到控制台输出。
接受值:
xterm
(默认值)VGA
css
GNOME终端
$ jobs_done jenkins --username USER https://example.com/jenkins
7
覆盖范围
启用代码覆盖率报告。
需要cobertura plugin
选项:
report_pattern
:必选,搜索XML覆盖率文件的模式。这些XML文件通常位于 cobertura格式,它也是 pytest-covxml输出(因为pytest-cov使用覆盖库)。健康
:可选,指定所需的方法、行和条件度量。任何省略的度量默认为80
不正常
:可选,指定所需的方法、行和条件度量。任何省略的度量默认为0
。低于这些阈值的生成被标记为不健康。失败
:可选,指定所需的方法、行和条件度量。任何省略的度量默认为0
。低于这些阈值的生成将标记为失败。
$ jobs_done jenkins --username USER https://example.com/jenkins
8
cron
要定期运行的生成计划。
$ jobs_done jenkins --username USER https://example.com/jenkins
9
自定义工作区
定义作业的自定义工作区目录。要保持与默认工作区目录相同的基本目录,请在其前面加上"workspace/"
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5870
说明_regex
用于搜索作业输出以获取描述的正则表达式。 如果找到匹配项,则第一组的内容将被设置为说明。
需要描述设置插件
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5871
显示名称
配置作业的显示名称。
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5872
电子邮件通知
发送失败生成的电子邮件。
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5873
排除
从矩阵中排除作业。
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5874
GIT
主项目的其他Git选项。
需要git插件
这里提供的选项与其他存储库共享
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5875
jsunit_模式
用于查找测试结果的jsunit文件模式列表。
需要jsunit插件
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5876
JUnit_模式
查找测试结果的JUnit文件模式列表。
需要xunit plugin
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5877
label_表达式
配置作业的标签表达式。
label表达式用于确定哪些工人可以运行作业。
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5878
矩阵
配置作业的变体。
JD_JENKINS_URL=https://example.com/jenkinsJD_JENKINS_USERNAME=jenkins-userJD_JENKINS_PASSWORD=some passwordJD_STASH_URL=https://example.com/stashJD_STASH_USERNAME=stash-userJD_STASH_PASSWORD=some passwordJD_EMAIL_USER=mail-sender@example.comJD_EMAIL_FROM=JobsDone Bot <mail-sender@example.com>JD_EMAIL_PASSWORD=email passwordJD_EMAIL_SERVER=smtp.example.comJD_EMAIL_PORT=5879
通知仓库
生成通过时通知存储实例。
如果没有给定参数,则使用在jenkins实例中设置的配置。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>0
参数
Jenkins作业的作业参数。
目前,只实现了选项和
字符串。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>1
单片机轮询
计划定期轮询供应链以获取更改,并触发生成。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>2
松弛度
使用slack配置通知。
- 在Slack上配置Jenkins集成
- 获得代币
- 使用此选项将作业配置为通知slack。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>3
超时
作业超时(分钟)。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>4
时间戳
在控制台输出的左侧显示时间戳。
需要时间戳插件
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>5
触发任务
在当前作业完成后触发其他作业。参数是可选的。
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>6
警告
配置CI作业中警告的解析和静态分析。
需要警告插件
$ git clone https://github.com/ESSS/jobs_done10.git $cd jobs_done10 $ git checkout <VERSION>7