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 天前
深入解析内存中的整数与浮点数存储
c语言·经验分享·笔记·visualstudio
聪明的笨猪猪1 天前
Java JVM “垃圾回收(GC)”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
润 下1 天前
C语言——深入解析C语言指针:从基础到实践从入门到精通(四)
c语言·开发语言·人工智能·经验分享·笔记·程序人生·其他
万悉科技2 天前
AI搜索引擎如何改变品牌信息曝光的游戏规则?
经验分享
我要学习别拦我~2 天前
柱状图的高级玩法:分组、堆叠、百分比对比
经验分享·信息可视化·数据可视化
阿部多瑞 ABU2 天前
技术报告:高仿真虚构内容对主流大模型的现实感幻觉测试
人工智能·经验分享·笔记·学习·ai写作
asdzx672 天前
驾驭Excel数据:使用C#将Excel导出为DataTable的实战指南
经验分享
Metaphor6922 天前
Java 获取 Excel 中工作表的名称
经验分享
芯片智造2 天前
在半导体制造中硅片的尺寸与其厚度有什么关系呢?
经验分享·芯片·半导体·硅片
芯片智造2 天前
在半导体制造中什么是晶圆退火工艺?
经验分享·芯片·半导体·晶圆退火