简体   繁体   中英

Configuring jobs using Artifactory in Jenkins with Jenkins Job DSL

I am trying to set up Artifactory in a Jenkins job that is generated with the Job DSL plugin .

The configuration looks like this:

  wrappers {
    colorizeOutput 'xterm'
    buildName '#${BUILD_NUMBER}-release'
    artifactoryGenericConfigurator {
      // Repository to deploy to.
      details {
        artifactoryName('artifactory.foo.bar.com')
        artifactoryUrl('https://artifactory.foo.bar.com/artifactory')
        deployReleaseRepository {
          keyFromSelect('')
          keyFromText('')
          dynamicMode(false)
        }
        deploySnapshotRepository {
          keyFromSelect('')
          keyFromText('')
          dynamicMode(false)
        }
        resolveReleaseRepository() {
          keyFromText('')
          keyFromSelect('')
          dynamicMode(false)
        }
        resolveSnapshotRepository() {
          keyFromText('')
          keyFromSelect('')
          dynamicMode(false)
        }
        userPluginKey('')
        userPluginParams('')

        useSpecs(true)
        uploadSpec {
          spec('''{
            "files": [
              {
                  "pattern": "app.tar.gz",
                  "target": "myrepo/app/${BUILD_NUMBER}-release",
                  "flat" : "false"
              }
            ]
          }''')
          filePath(null)
        }
        downloadSpec {
          spec('')
          filePath(null)
        }
      }

      deployPattern('')
      deployBuildInfo(true)
      includeEnvVars(false)
      discardOldBuilds(false)
      discardBuildArtifacts(false)
      multiConfProject(false)
      deployerCredentialsConfig(null)
      resolverCredentialsConfig(null)
      resolverDetails(null)
      resolvePattern(null)
      matrixParams(null)

      envVarsPatterns {
        includePatterns('*')
        excludePatterns('*PASSWORD*,*password*,*secret*,*key*')
      } 
      asyncBuildRetention(false)
      artifactoryCombinationFilter(null)
      customBuildName(null)
      overrideBuildName(false)
    }
  }

However, this config always leads to this error, that is a bit confusing, since I do not know which part of my config is wrong here.

FATAL: No Artifactory server configured for null. Please check your configuration. java.io.IOException: No Artifactory server configured for null. Please check your configuration. at org.jfrog.hudson.util.RepositoriesUtils.validateServerConfig(RepositoriesUtils.java:191) at org.jfrog.hudson.generic.ArtifactoryGenericConfigurator.setUp(ArtifactoryGenericConfigurator.java:325) at hudson.model.Build$BuildExecution.doRun(Build.java:157) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504) at hudson.model.Run.execute(Run.java:1724) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:421)

Here's an important detail: if , after generating my job, I go to the Jenkins configuration page for this job, and save the config without changing anything, then this config works . I think I am just using the wrong default values for all the options .

NB: I have to specify all of these, since they are listed as "mandatory" in the API Viewer... http://jenkins.foo.bar.com/plugin/job-dsl/api-viewer/index.html

I have been looking at the source code for the plugin , and while I could find some context for my error message, I couldn't diagnose the exact problem in my DSL script.

I'm just working on Job DSL examples.

You need to configure an Artifactory server in Artifactory Plugin Configuration . Then, in artifactoryName field, put the server id. artifactoryUrl field is not necessary. All other fields, like useSpecs should be outside detail scope.

If you want to configure repository in your seed job, please change dynamicMode to true.

Finally, please notice that there are no snapshot repositories since they are not supported in Artifactory Gradle jobs in Jenkins.

In the end, you'll have something like this:

details { // This is the Artifactory deployer details
    artifactoryName SERVER_ID // The server ID from Artifactory Plugin Configuration
    deployReleaseRepository {
        keyFromText 'libs-release-local' // The deploy release repository
        dynamicMode true // true if you want to use `keyFromText`
    }

} // This is the Artifactory resolver details
resolverDetails {
    artifactoryName SERVER_ID // The server ID from Artifactory Plugin Configuration
    resolveReleaseRepository {
        keyFromText 'libs-release' // The resolve release repository
        dynamicMode true // true if you want to use `keyFromText`
    }
}
useSpecs true
...

Update:

in the latest release v2.15.0 we made some changes that make this configuration a bit easier. For example, the dymamicMode is not necessary now. For more information please refer to our project examples .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM