Answer a question

I followed the example given in this page to download artifacts from JFrog artifactory: https://www.jfrog.com/confluence/display/JFROG/Scripted+Pipeline+Syntax#ScriptedPipelineSyntax-UploadingandDownloadingFiles

But I have been getting NullPointerException. Below is the script output and error:

[Pipeline] echo
download spec {
    "files": [
        {
            "pattern": "aod-libs-release/path-to-artifact/deployment/DM-DP-V3A.24-RELEASE/deployment-DM-DP-V3A.24-RELEASE.zip",
            "target": "./artifacts"
        }, {
            "pattern": "aod-libs-release/path-to-artifact/dm-auth-web-services/DM-AU-V3A.88-RELEASE/dm-auth-web-services-DM-AU-V3A.88-RELEASE.war",
            "target": "./artifacts"
        }
    ]
}
[Pipeline] echo
artifactory server org.jfrog.hudson.pipeline.common.types.ArtifactoryServer@66026154
[Pipeline] newBuildInfo
[Pipeline] artifactoryDownload
[Pipeline] End of Pipeline
java.lang.NullPointerException
    at org.jfrog.hudson.pipeline.common.executors.GenericDownloadExecutor.execute(GenericDownloadExecutor.java:52)
    at org.jfrog.hudson.pipeline.scripted.steps.DownloadStep$Execution.runStep(DownloadStep.java:67)
    at org.jfrog.hudson.pipeline.scripted.steps.DownloadStep$Execution.runStep(DownloadStep.java:53)
    at org.jfrog.hudson.pipeline.ArtifactorySynchronousNonBlockingStepExecution.run(ArtifactorySynchronousNonBlockingStepExecution.java:54)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

Below is my jenkins pipeline script

def artifactoryServer = Artifactory.server("Artifactory-instance-id")
artifactoryServer.connection.timeout = 300
def artifactDownloadSpec = """{
    "files": [
        {
            "pattern": "aod-libs-release/path-to-artifact/deployment/${env.DP_VERSION}/deployment-${env.DP_VERSION}.zip",
            "target": "./artifacts"
        }, {
            "pattern": "aod-libs-release/path-to-artifact/dm-auth-web-services/${env.VERSION}/dm-auth-web-services-${env.VERSION}.war",
            "target": "./artifacts"
        }
    ]
}"""

echo "download spec " + artifactDownloadSpec
echo "artifactory server " + artifactoryServer
artifactoryServer.download spec: artifactDownloadSpec

I googled for GenericDownloadExecutor.java and found below code, but cannot figure out what I am missing that line 52 needed. Looks like a field is not set.

https://github.com/jenkinsci/artifactory-plugin/blob/master/src/main/java/org/jfrog/hudson/pipeline/common/executors/GenericDownloadExecutor.java

Please help. Thank you in advance, and have a great day.

Answers

Running artifactoryServer.download step requires using an agent. For example:

Jenkins scripted pipeline

node {
  ...
  artifactoryServer.download spec: artifactDownloadSpec
  ...
}

Jenkins declarative pipeline

The recommended way is to use the rtDownload step, however, if you still want to use artifactoryServer.download:

pipeline {
    agent any // <- Make sure there is an active agent
    stages {
        stage('Example') {
            steps {
                script {
                  ...
                  artifactoryServer.download spec: artifactDownloadSpec
                  ...
                }
            }
        }
    }
}

Read more:

  1. Uploading and Downloading Files
  2. Scripted pipeline example
  3. Declarative pipeline example
  4. Scripted pipeline inside declarative pipeline example - Less recommended, but this example is like your case
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐