phoenix
phoenix

Reputation: 617

Is there a jenkins job-dsl block/code for defining Gradle-Artifactory plugin configuration?

In jenkins job, I use the gradle-artifactory plugin to publish the artifact to specific path (which is mentioned in build.gradle of the git project) in Artifactory.
I wanted to have my Jenkins jobs through job-dsl. What would be the job-dsl code/block for gradle-artifactory plugin configuration?
I tried to use ArtifactoryGradleConfigurator class but it did not work.

Upvotes: 1

Views: 595

Answers (2)

crasp
crasp

Reputation: 743

The artifactory plugin is not yet supportet by job dsl. What you need to do is create the according XML config by yourself via the configure block. Here is an example for you where you can start:

job('artifactory-config') {
  configure {
    it / buildWrappers / 'org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator' {
      deployMaven 'false'
      deployIvy 'false'
      deployBuildInfo 'true'
      includeEnvVars 'false'
      deployerCredentialsConfig {
        credentialsId 'foobar'
        overridingCredentials 'false'
      }
    }
  }
}

The actual configuration you need to do is a bit more extensive. Just have a look at the config.xml of your job, there you will find the XML tag for ArtifactoryGradleConfigurator. It will look like this:

<project>
  <buildWrappers>
    <org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator">
      <deployMaven>false</deployMaven>
      <deployIvy>false</deployIvy>
      <deployBuildInfo>true</deployBuildInfo>
      <includeEnvVars>false</includeEnvVars>
      <deployerCredentialsConfig>
        <credentials>
          <username></username>
          <password></password>
        </credentials>
        <credentialsId></credentialsId>
        <overridingCredentials>false</overridingCredentials>
      </deployerCredentialsConfig>
      <resolverCredentialsConfig>
        <credentials>
          <username></username>
          <password></password>
        </credentials>
        <credentialsId></credentialsId>
        <overridingCredentials>false</overridingCredentials>
      </resolverCredentialsConfig>
    </org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator>
  </buildWrappers>
</project>

One important thing for you to know is, you do not need to configure the whole block. But when you miss any important XML tag, the job will be generated, but you will not see the configuration in the UI. Just try to get the XML to be generated 1:1. The Jenkins Job DSL Playground is a nice tool to help you do that.

Upvotes: 1

JBaruch
JBaruch

Reputation: 22893

Nice thing about the Jenkins Artifactory plugin for Gradle is that all it does is applying Gradle Artifactory plugin (which is, of course, all code – Gradle DSL). So instead of applying the plugin from Jenkins UI you can apply it directly in Gradle, in code.

Upvotes: 0

Related Questions