Custom WAR Packager(CWP)允许使用YAML规范构建即用型Jenkins包。该工具可生成Docker镜像、WAR文件和https://github.com/jenkinsci/jenkinsfile-runner Docker镜像(也称为单次运行Jenkins主节点)。这些包可包含Jenkins核心、插件、额外库,以及通过Groovy Hook脚本或https://github.com/jenkinsci/configuration-as-code-plugin YAML文件的自配置。
更多信息请参见此博客文章。
Custom WAR Packager提供了一个Docker镜像,其中捆绑了所有必需的工具。
shelljava -jar custom-war-packager-cli.jar -configPath=mywar.yml -version=1.0-SNAPSHOT -tmpDir=tmp
构建后,生成的WAR文件将被放置在tmp/output/target/${artifactId}.war。
要使用此配置以演示模式运行工具,请使用以下命令:
shelljava -jar war-packager-cli.jar -demo
不带选项调用工具可获取完整的CLI选项列表。
Maven插件运行打包器并生成工件。工件将被放置在target/custom-war-packager-maven-plugin/output/target/${bundle.artifactId}.war,并添加到项目工件中。
xml<build> <plugins> <plugin> <groupId>io.jenkins.tools.custom-war-packager</groupId> <artifactId>custom-war-packager-maven-plugin</artifactId> <version>@project.version@</version> <executions> <execution> <phase>package</phase> <goals> <goal>custom-war</goal> </goals> <configuration> <configFilePath>spotcheck.yml</configFilePath> <warVersion>1.1-SNAPSHOT</warVersion> </configuration> </execution> </executions> </plugin> </plugins> </build>
注意,此插件调用Maven-in-Maven,且不会将构建选项传递给插件。可使用配置文件配置下游构建器。
示例:
yamlbundle: groupId: "io.github.oleg-nenashev" artifactId: "mywar" description: "Just a WAR auto-generation-sample" vendor: "Jenkins project" buildSettings: docker: base: "jenkins/jenkins:2.121.1" tag: "jenkins/demo-external-task-logging-elk" build: true war: groupId: "org.jenkins-ci.main" artifactId: "jenkins-war" source: version: 2.107 plugins: - groupId: "org.jenkins-ci.plugins" artifactId: "matrix-project" source: version: 1.9 - groupId: "org.jenkins-ci.plugins" artifactId: "durable-task" source: git: https://github.com/jglick/durable-task-plugin.git branch: watch-JENKINS-38381 - groupId: "org.jenkins-ci.plugins.workflow" artifactId: "workflow-durable-task-step" source: git: https://github.com/jglick/workflow-durable-task-step-plugin.git commit: 6c424e059bba90fc94a9c1e87dc9c4a324bfef26 - groupId: "io.jenkins" artifactId: "configuration-as-code" source: version: 0.11-alpha-rc373.933033f6b51e libPatches: - groupId: "org.jenkins-ci.main" artifactId: "remoting" source: git: https://github.com/jenkinsci/remoting.git systemProperties: { jenkins.model.Jenkins.slaveAgentPort: "50000", jenkins.model.Jenkins.slaveAgentPortEnforce: "true"} groovyHooks: - type: "init" id: "initScripts" source: dir: scripts casc: - id: "jcasc-config" source: dir: jenkins.yml
还有更多可用选项。有关示例,请参见链接的演示。
该插件支持https://github.com/jenkinsci/jep/tree/master/jep/309%E4%B8%AD%E6%8F%8F%E8%BF%B0%E7%9A%84%E7%89%A9%E6%96%99%E6%B8%85%E5%8D%95%EF%BC%88BOM%EF%BC%89%E4%BD%9C%E4%B8%BA%E8%BE%93%E5%85%A5%E3%80%82
如果定义了BOM,Custom WAR Packager将从中加载插件和组件依赖。以下示例从BOM获取输入并生成自定义WAR和Docker包。
yamlbundle: groupId: "io.jenkins.tools.war-packager.demo" artifactId: "bom-demo" buildSettings: bom: bom.yml environment: aws docker: base: "jenkins/jenkins:2.121.2" tag: "jenkins/cwp-bom-demo" build: true
此类配置的示例可在https://github.com/jenkinsci/artifact-manager-s3-plugin/pull/20%E8%8E%B7%E5%8F%96%E3%80%82
为简化开发版本的打包,可以将Custom War Packager链接到POM文件,以便从中获取要捆绑的插件。
如果设置了pom选项,将添加所有依赖项,包括测试依赖项。当前父项也将被捆绑,除非设置了pomIgnoreRoot标志。
yamlbundle: groupId: "io.jenkins.tools.war-packager.demo" artifactId: "pom-input-demo" buildSettings: pom: pom.xml pomIgnoreRoot: true war: groupId: "org.jenkins-ci.main" artifactId: "jenkins-war" source: version: 2.121.1
示例可在此处获取。
特性:
当前,该工具处于alpha状态。它有一些严重的限制:
jenkins.util.SystemProperties类
libPatches步骤仅捆绑指定的JAR文件,而非其依赖项
如果依赖项与基础WAR文件相比有变化,则也需要显式打包这些依赖项
libExcludes删除不再需要的依赖项您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务