Jenkins运维之路(制品上传)

需要安装插件Nexus Artifact Uploader,然后再Jenkins密钥管理处添加好Nexus账号密码

1.代码片段

1.1 上传单个文件

bash 复制代码
//......此处省略
        stage('Upload to Nexus') {
            steps {
                script {
                    // 使用之前生成的 version 变量
                    nexusArtifactUploader artifacts: [
                        [
                            artifactId: 'basejar', // 替换为您的 artifactId
                            classifier: '',
                            file: 'target/spring-boot-3-hello-world-1.0.0-SNAPSHOT.jar', // 替换为您的文件路径
                            type: 'jar' // 根据您的文件类型进行修改
                        ],
                				[
                    		artifactId: 'basejar', // 同样的 artifactId,或根据需要修改
                    		classifier: 'pom',
                    		file: 'pom.xml', // 指向您的 pom.xml 文件
                    		type: 'pom' // 文件类型为 pom
                				]
                    ],
                    //文件file类型有jar,pom,war,zip,tar.gz
                    credentialsId: 'Nexus3-DevOps',
                    groupId: 'top.xxx',
                    nexusUrl: 'registryv.xxxx.top',
                    nexusVersion: 'nexus3',
                    protocol: 'https',
                    repository: 'DevopsArtifact',
                    version: "${_tag}"
                }
            }
        }
//....此处省略

1.2 上传zip文件

有时候你的代码是会做一个分离的 比如你的依赖jar放在了lib里面,resource放了配置文件

bash 复制代码
        stage('Build') {
            when {
                expression { 
                    // 检查 BRANCH_TAG 是否不以 'rel-' 开头
                    return !params.BRANCH_TAG.startsWith('rel-')
                }
            }
            steps {
                ansiColor('xterm') { // 启用 AnsiColor
                    echo "${GREEN}项目开始构建${RESET}"
                    echo "Building"
                }
                sh 'mvn clean package -Dmaven.test.skip=true'
								sh 'tar zcvf spring-boot-3-hello-world-1.0.0-SNAPSHOT.tar.gz target/spring-boot-3-hello-world-1.0.0-SNAPSHOT.jar pom.xml target/lib target/resource'
            }
        }
        stage('Upload to Nexus') {
            steps {
                script {
                    // 使用之前生成的 version 变量
                    nexusArtifactUploader artifacts: [
                        [
                            artifactId: 'basejar', // 替换为您的 artifactId
                            classifier: '',
                            file: 'spring-boot-3-hello-world-1.0.0-SNAPSHOT.tar.gz', // 替换为您的文件路径
                            type: 'tar.gz' // 根据您的文件类型进行修改
                        ],
                				[
                    		artifactId: 'basejar', // 同样的 artifactId,或根据需要修改
                    		classifier: 'pom',
                    		file: 'pom.xml', // 指向您的 pom.xml 文件
                    		type: 'pom' // 文件类型为 pom
                				]
                    ],
                    //文件file类型有jar,pom,war,zip,tar.gz
                    credentialsId: 'Nexus3-DevOps',
                    groupId: 'top.xxx',
                    nexusUrl: 'registryv.xxx.top',
                    nexusVersion: 'nexus3',
                    protocol: 'https',
                    repository: 'DevopsArtifact',
                    version: "${_tag}"
                }
            }
        }

2.查看上传结果

image-20250919173150571

3.制品下载

3.1 参数化构建设置

image-20250922174427350

image-20250922174523253

bash 复制代码
//上面定义的nexus3能够将你拉取到的列表存入到变量当中,这里在建立一个私服变量将上面定义参数拉取到的内容转换成字符串
String artifactUrl = "${env.artifactUrl}"
sh " wget ${artifactUrl} && ls " // Nexus3制品库无认证
//sh " wget --user=admin --password=Qwer@123 ${artifactUrl} && ls "   // Nexus3制品库有认证
相关推荐
聊言青7 小时前
2026USNEWS top200美国大学分布地图
经验分享·考研·github
zore_c9 小时前
【C语言】数据在内存中的存储(超详解)
c语言·开发语言·数据结构·经验分享·笔记
TeleostNaCl9 小时前
Android TV | 一种不跳出应用指定页面的类 Monkey 的 Android TV 压测脚本
android·经验分享·压力测试
weixin_537217069 小时前
linux运维资源合集
经验分享
纵有疾風起9 小时前
【C++—STL】红黑树底层封装与set/map模拟实现
开发语言·c++·经验分享·面试·开源·stl
狮子座的男孩10 小时前
js函数高级:03、详解原型与原型链(原型、显式原型与隐式原型、原型链、原型链属性、探索instanceof、案例图解)及相关面试题
前端·javascript·经验分享·显示原型与隐式原型·原型链及属性·探索instanceof·原型与原型链图解
云半S一11 小时前
春招准备之测试基础理论篇
经验分享·笔记·功能测试·测试覆盖率
春风伴我余生12 小时前
CDN:从“网络加速器”到“网络安全盾”的进化之路
经验分享
弘毅 失败的 mian12 小时前
Linux 基本工具详解
linux·运维·服务器·经验分享·笔记
弘毅 失败的 mian12 小时前
Linux 编程第一个小程序:进度条
linux·经验分享·笔记·小程序·apache