使用 Jenkins Job DSL 在 Jenkins 中使用 Artifactory 配置作业

Configuring jobs using Artifactory in Jenkins with Jenkins Job DSL

我正在尝试设置 Artifactory in a Jenkins job that is generated with the Job DSL plugin

配置如下所示:

  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)
    }
  }

然而,这个配置总是导致这个错误,这有点令人困惑,因为我不知道我的配置哪里有问题。

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)

这里有一个重要的细节:if,在生成我的作业后,我转到该作业的 Jenkins 配置页面,并保存配置而不做任何更改,然后这个配置工作。我想我只是对所有选项使用了错误的默认值。

注意:我必须指定所有这些,因为它们在 API 查看器中列为 "mandatory"... http://jenkins.foo.bar.com/plugin/job-dsl/api-viewer/index.html

我一直在查看 source code for the plugin,虽然我可以为我的错误消息找到一些上下文,但我无法在我的 DSL 脚本中诊断出确切的问题。

我正在处理作业 DSL 示例。

您需要在 Artifactory Plugin Configuration 中配置 Artifactory 服务器。 然后,在 artifactoryName 字段中,输入服务器 ID。 artifactoryUrl 字段不是必需的。所有其他字段,如 useSpecs 应该在 detail 范围之外。

如果您想在种子作业中配置存储库,请将 dynamicMode 更改为 true。

最后,请注意没有快照存储库,因为 Jenkins 中的 Artifactory Gradle 作业不支持它们。

最后,你会得到这样的结果:

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
...

更新:

在最新版本 v2.15.0 中,我们进行了一些更改,使此配置更容易一些。例如,现在不需要 dymamicMode。欲了解更多信息,请参阅我们的 project examples.