title: How to pass username password to Gradle to upload artifacts to Nexus from a Jenkins pipeline
body: <p>I need to upload artifacts to Nexus from a Jenkins declarative pipeline. There is a <a href="https://support.sonatype.com/hc/en-us/articles/227256688-How-do-I-configure-the-Nexus-Jenkins-Plugin" rel="nofollow noreferrer">Nexus plugin</a> that I can't use because it doesn't allow to publish SNAPSHOTs. Therefore I have to upload them directly through the Gradle upload task. The problem is that I am getting a 401 error code from Nexus and it seems the nexus user and passwords aren't being passed from the pipeline to the <code>./gradlew upload</code> task.</p>
  
  <p>This is my current configuration:</p>
  
  <p><strong>Pipeline</strong></p>
  
  <pre><code>withCredentials([usernamePassword(credentialsId: 'asdf23432-fe69-1234-2222-ffa65yteec2c', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USER')]) {
      sh "./gradlew upload --debug"
  }
  </code></pre>
  
  <p><strong>Gradle</strong>: In the ext section I try to access the NEXUS_USER and NEXUS_PASSWORD variables from the withCredentials step.</p>
  
  <pre><code>ext{
      nexusUser = System.properties['NEXUS_USER']
      nexusPassword = System.properties['NEXUS_PASSWORD']
  }
  
  uploadArchives {
      repositories {
          mavenDeployer {
              snapshotRepository(url: 'http://somerepo'){
                  authentication(userName: nexusUser, password: nexusPassword)
              }
          }
      }
  }
  </code></pre>