You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make'
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
//该sh步骤调用该make命令, 只有在命令返回零退出代码时才会继续。任何非零退出代码将失败Pipeline。
//archiveArtifacts捕获与include pattern( **/target/*.jar) 匹配的文件, 并将它们保存到Jenkins主文件以供以后检索。
//存档工件不能替代使用诸如Artifactory或Nexus之类的外部工件存储库, 只能用于基本报告和文件归档。
}
}
stage('Test') {
steps {
/* `make check` returns non-zero on test failures,
* using `true` to allow the Pipeline to continue nonetheless
*/
sh 'make check || true'
junit '**/target/*.xml'
//运行自动化测试是任何成功的连续传送过程的重要组成部分。因此, Jenkins有许多插件提供的测试记录, 报告和可视化设备 。在基本层面上, 当有测试失败时, 让Jenkins在Web UI中记录报告和可视化的故障是有用的。
//下面的示例使用junit由JUnit插件提供的步骤。
//在下面的示例中, 如果测试失败, 则Pipeline被标记为“不稳定”, 如Web UI中的黄色球。根据记录的测试报告, Jenkins还可以提供历史趋势分析和可视化。
}
}
stage('Deploy') {
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
//访问该currentBuild.result变量允许Pipeline确定是否有任何测试失败。在这种情况下, 值将是 UNSTABLE。
}
}
steps {
sh 'make publish'
}
}
//部署可能意味着各种步骤, 具体取决于项目或组织的要求, 并且可能是从构建的工件发送到Artifactory服务器, 将代码推送到生产系统的任何步骤。
//在Pipeline示例的这个阶段, “构建”和“测试”阶段都已成功执行。实际上, “部署”阶段只能在上一阶段成功完成, 否则Pipeline将早退。
}
}