title: Declarative Jenkinsfile using separate stages for Maven/Gradle build and publish to Artifactory
body: <p>EDIT: Sorry about formatting :( I'm new to this.. will try to clean it up.</p>
  
  <p>I'm using a declarative Jenkinsfile to build and publish Maven and Gradle artifacts with buildInfo to Artifactory trying to separate each action (stage1=build, stage2=publish) in distinct stages but am unable to figure out how to do so.</p>
  
  <p>Trying to figure out a working Declarative Pipeline syntax code to use with Artifactory to separate build and publishing stages. All the examples I've found are either incomplete, non-working or for scripted pipeline only.</p>
  
  <p>I've tried the instructions found here <a href="https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins" rel="nofollow noreferrer">https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins</a></p>
  
  <p>For Maven, setting 'deployArtifacts: false' in the rtMavenDeployer directive results in the buildinfo not being published, but the artifact is still deployed using goals 'clean install'.</p>
  
  <blockquote>
    <p>org.jfrog.build.extractor.maven.BuildInfoClientBuilder - Deploying >artifact: xxx</p>
  </blockquote>
  
  <p>In the log we see (with deployArtifacts: false):
  Artifactory Build Info Recorder: publish build info set to false, build info will not be published...</p>
  
  <pre><code>steps {
          rtMavenDeployer ( 
  ... 
  deployArtifacts: false )
  </code></pre>
  
  <p>in a later stage we use 
  rtPublishBuildInfo () to publish the actual buildInfo to Artifactory.</p>
  
  <p>I've also tried to create two separate rtMavenDeployer's to be used for build and one for deploy.</p>
  
  <p>for ex.</p>
  
  <pre><code>rtMavenDeployer (
  id: builder
  deployArtifacts: false
  )
  
  rtMavenDeployer (
  id: deployer
  deployArtifacts: true
  )
  </code></pre>
  
  <p>Later references in respective build and publish stages using 
  BUILD STAGE:</p>
  
  <pre><code>rtMavenRun(
  deployerId: 'builder'
  goals: 'clean install'
  )
  </code></pre>
  
  <p>DEPLOY STAGE:</p>
  
  <pre><code>rtMavenRun(
  deployerId: 'deployer'
  goals: 'install'
  )
  rtPublishBuildInfo()
  </code></pre>
  
  <p>Resulting in duplicate buildInfo in Artifactory and x2 inflated registered artifacts...</p>
  
  <p>Is there a clear way for this separation of actions in a declarative pipeline?</p>
  
  <p>Expect to be able to build an artifact using Declarative Pipeline syntax in one stage and deploy the actual Maven/Gradle artifact with buildInfo at a later stage.</p>
  
  <p>This is how it's done in separate stages in a scripted pipeline from what I understand:</p>
  
  <pre><code>    stage ('Test') {
          rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean test'
      }
  
      stage ('Install') {
          rtMaven.run pom: 'maven-example/pom.xml', goals: 'install', buildInfo: buildInfo
      }
  
      stage ('Deploy') {
          rtMaven.deployer.deployArtifacts buildInfo
      }
  
      stage ('Publish build info') {
          server.publishBuildInfo buildInfo
      }
  }
  </code></pre>