当前位置: 首页 > 知识库问答 >
问题:

在Jenkins管道中上传工件期间,有没有任何方法可以更改Nexus URL路径

阎渝
2023-03-14

我正在尝试使用Jenkins管道将工件上传到nexus,在Jenkins管道中,整个管道在最后阶段结束。其中工件没有上载到nexus存储库。

举个例子:http://localhost:8081/nexus/content/repositories/releases是我现有的存储库,并且正在尝试将工件上载到其中。但是当我开始Jenkins管道构建时,看到url到达:http://localhost:8081/nexus/content/repositories/repositories/releases。我很困惑上面URL中的“存储库”是从哪里来的。

正在上载项目BLT-Server.WAR已启动....

GroupID:空

Artifactid:blt-server

存储库:版本

下载:http://localhost:8081/nexus/content/repositories/repository/releases/maven-metadata.xml

上传:http://localhost:8081/nexus/content/repositories/repository/releases/blt-server/0.0.1-snapshot/blt-server-0.0.1-20190906.152523-1.war

10%已完成(5.5MB/55MB)。

20%已完成(11 MB/55 MB)。

完成30%(17 MB/55 MB)。

70%已完成(39 MB/55 MB)。

80%已完成(44 MB/55 MB)。

90%已完成(50 MB/55 MB)。

我希望在上传war文件时url应该是这样的:http://localhost:8081/nexus/content/repositories/releases,但事实并非如此。

下面是我的管道脚本:

pipeline {
    agent {
        label "master"
    }
    tools {
    maven "Maven-3.5.2" 
 }
 environment {
     NEXUS_VERSION = "nexus3"
     NEXUS_PROTOCOL = "http"
     NEXUS_URL = "localhost:8081/nexus/content/repositories"
     NEXUS_REPOSITORIES = "releases"
     NEXUS_CREDENTIAL_ID = "SonatypeREMNexus3"
     CREDENTIALSID= "********confidential***"
 }
 stages {
     stage("clone bitbucket") {
         steps { 
             checkout(
        [
            $class: 'GitSCM', 
            branches: [[name: 'master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [
                [$class: 'RelativeTargetDirectory', relativeTargetDir: 'build'] 
            ], 
            submoduleCfg: [], 
            userRemoteConfigs: [
                [
                    credentialsId: '********confidential***',
                    url: 'ssh://git@bitbucket.confidential:7999/blt/blt-server.git'
                ]
            ]
        ]
    )

             }
     }
     stage('Build & Test') {
         steps {
             script {
        withMaven(
            options: [artifactsPublisher(disabled: true)],
            jdk: 'JAVA-1.8.0_152',
            maven: 'Maven-3.5.2') {
            sh "mvn clean package -f build/pom.xml"
        }
     }
    }
     }
     stage("publish to nexus") {
         steps {
             script {
             pom = readMavenPom file: "build/pom.xml";
             filesByGlob = findFiles(glob: "build/target/*.${pom.packaging}");
             echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
             artifactPath = filesByGlob[0].path;
             artifactExists = fileExists artifactPath;
             if(artifactExists) {
                 echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version: ${pom.version}"
                 nexusArtifactUploader(
                 nexusVersion: NEXUS_VERSION,
                 protocol: NEXUS_PROTOCOL,
                 nexusUrl: NEXUS_URL,
                 groupId: pom.groupId,
                 version: pom.version,
                 repository: NEXUS_REPOSITORIES,
                 credentialsId: NEXUS_CREDENTIAL_ID,
                 artifacts: [
                     [artifactId: pom.artifactId,
                     classifier: '',
                     file: artifactPath,
                     type: pom.packaging],
                     [artifactId: pom.artifactId,
                     classifier: '',
                     file: "build/pom.xml",
                     type: "pom"]
                ]
            );
                 } else {
                     error "*** File: ${artifactPath}, could not be found";
                 }

             }
         }
     }
     }

 }

共有1个答案

崔绍辉
2023-03-14

问题就出在这里:

NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "localhost:8081/nexus/content/repositories"

指定的Nexus版本是Nexus 3,但URL遵循Nexus 2格式。

Nexus 3使用URL格式/repository/ / ,而Nexus 2使用/content/repositories/ /

如果您使用的是Nexus2,只需更新nexus_version=“nexus2”版本。

如果在联系3上:

  1. 将Nexus Artifact Uploader插件升级到2.6或更高版本。
  2. localhost:8081/Nexus/content/repositories替换为localhost:8081/Nexuslocalhost:8081(适用于您的Nexus存储库)。

您还可以将Nexus3配置为使用旧版URL路径。

 类似资料:
  • 我正在运行下面的管道,它为DotNetCore2.2运行“构建+声呐扫描程序分析”阶段 舞台设置如下 我已经按照Sonarqube文档的建议在全局配置中安装了该工具 该dll存在并且权限已分配给Jenkins 该dll是可执行的 在该路径中手动运行时的dll-它运行 提前感谢你的帮助。

  • 对 YAML 定义的 Azure DevOps 管道进行更改时,将更改推送到分支只是为了看到生成失败并显示分析错误(YAML 有效,但管道定义无效),然后尝试试错解决问题,这可能会非常繁琐。 如果反馈循环可以通过本地分析和验证管道定义来缩短,那就太好了;基本上是一个了解Azure管道中可以定义的各种资源等的linter。但是,我还没有找到任何可以做到这一点的工具。 在某个地方有这样的工具吗?

  • 在Jenkins创建了一个多分支管道后,我可以很容易地告诉它轮询任何分支的更改或添加,它将自动为这些分支创建工作岗位并构建这些分支。我告诉多分支作业也要发现标记,因此它会自动为每个标记创建作业,这很好。 詹金斯有没有一种干净的方法来自动构建这些标签,而不是我手动触发它们?正如您在下面所看到的,标签的作业就在那里,但我必须手动构建它。

  • 我在Jenkins管道中使用下面的Groovy脚本来调用自由风格的作业,但它最终出现了“没有这样的DSL方法‘构建’”错误。

  • 我试图制作一些组件,我是React的新手,我尝试了一些基础知识,比如创建存储

  • 我需要上传超过100 MB的文件,。我正在使用Linux,CentOS 7。 我做到了: 检查路径php.iniphpinfo() 在php.ini中添加 重启LAMP服务器()并运行phpnfo()进行检查,但没有任何变化。虽然php.ini改变了。 重启我的电脑并启动LAMP服务器,但phpnfo()仍然没有变化。 我找到了一些添加additional.ini.files的解决方案,但是在我的