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制品库有认证
相关推荐
三流架构师1 小时前
Illustrator教程资源合集
经验分享
讯捷蓝达2 小时前
安徽寄修案例分享 IBM V3700存储无法访问 控制器node1 578报错和node2 不识别且IP不通
经验分享
字节跳动的猫4 小时前
2026四款AI 部署难问题破解
经验分享
Metaphor6926 小时前
Java 中文 PDF 排版利器:文字对齐精讲
经验分享
浩瀚地学6 小时前
【Java】集合-Collection
java·开发语言·经验分享·笔记·学习
来鼓AI6 小时前
2025年获客工具3大趋势:自动化、智能化、一体化
经验分享
Teacher.chenchong6 小时前
全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用
经验分享
CodeCaptain7 小时前
dify的知识检索在编排中的释义与作用
经验分享·ai·dify
中屹指纹浏览器8 小时前
2026 指纹浏览器技术深度剖析:沙箱隔离与 IP 协同适配的实现方案
经验分享·笔记
qq77788898 小时前
PDF批量加马赛克软件怎么用?支持多区域不同值批量打码解密加密文件
经验分享