简体   繁体   English

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

[英]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 . 我试图在由Job DSL插件生成的Jenkins作业中设置Artifactory

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. 严重:没有将Artifactory服务器配置为null。 Please check your configuration. 请检查您的配置。 java.io.IOException: No Artifactory server configured for null. java.io.IOException:没有将Artifactory服务器配置为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) 在org.jfrog.hudson.generic.ArtifactoryGenericConfigurator.setUp(ArtifactoryGenericConfigurator.java:325)上的org.jfrog.hudson.util.RepositoriesUtils.validateServerConfig(RepositoriesUtils.java:191)在hudson.model.Build $ BuildExecution.doRun(Build .java:157),位于hudson.model.FreeStyleBuild.run(FreeStyleBuild.java: 43)在hudson.model.ResourceController.execute(ResourceController.java:97)在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 . 这是一个重要的细节: 如果在生成我的作业之后,我转到该作业的Jenkins配置页面,并保存配置而不更改任何内容, 则该配置有效 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 注意:我必须指定所有这些,因为它们在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. 我一直在寻找插件源代码 ,尽管可以找到一些关于错误消息的上下文,但是我无法在DSL脚本中诊断出确切的问题。

I'm just working on Job DSL examples. 我正在研究Job DSL示例。

You need to configure an Artifactory server in Artifactory Plugin Configuration . 您需要在Artifactory Plugin Configuration中配置 Artifactory服务器。 Then, in artifactoryName field, put the server id. 然后,在artifactoryName字段中,输入服务器ID。 artifactoryUrl field is not necessary. artifactoryUrl字段不是必需的。 All other fields, like useSpecs should be outside detail scope. 所有其他字段(如useSpecs都应在detail范围之外。

If you want to configure repository in your seed job, please change dynamicMode to true. 如果要在种子作业中配置存储库,请将dynamicMode更改为true。

Finally, please notice that there are no snapshot repositories since they are not supported in Artifactory Gradle jobs in Jenkins. 最后,请注意,由于Jenkins的Artifactory Gradle作业不支持快照存储库,因此没有快照存储库。

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. 在最新版本v2.15.0中,我们进行了一些更改,使此配置更加容易。 For example, the dymamicMode is not necessary now. 例如,现在不需要dymamicMode。 For more information please refer to our project examples . 有关更多信息,请参阅我们的项目示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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