Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59567

Server Credentials created from Jenkins credentials don't show up in maven settings.xml

      Also on SO: https://stackoverflow.com/questions/58139761/pipeline-maven-plugin-not-replacing-servers-in-global-settings-xml-from-jenkin

      hard coding "<servers></servers>" in the config file works but configuring "Server Credentials" from jenkins credentials is not working. I tried with and without "Replace all"

          [JENKINS-59567] Server Credentials created from Jenkins credentials don't show up in maven settings.xml

          red der created issue -

          red der added a comment -

          I linked the wrong ticket to this. This is a different issue than the one described in the ticket I linked initially

          red der added a comment - I linked the wrong ticket to this. This is a different issue than the one described in the ticket I linked initially
          red der made changes -
          Description Original: Looks like pretty much this same issue: https://issues.jenkins-ci.org/browse/JENKINS-29805

          Also on SO: [https://stackoverflow.com/questions/58139761/pipeline-maven-plugin-not-replacing-servers-in-global-settings-xml-from-jenkin]

          hard coding "<servers></servers>" in the config file works but configuring "Server Credentials" from jenkins credentials is not working. I tried with and without "Replace all"
          New: Also on SO: [https://stackoverflow.com/questions/58139761/pipeline-maven-plugin-not-replacing-servers-in-global-settings-xml-from-jenkin]

          hard coding "<servers></servers>" in the config file works but configuring "Server Credentials" from jenkins credentials is not working. I tried with and without "Replace all"
          Summary Original: Credentials don't show up in maven settings.xml (regression) New: Server Credentials created from Jenkins credentials don't show up in maven settings.xml

          Cyrille Le Clerc added a comment - - edited

          Cross posting answer already made on https://groups.google.com/forum/#!topic/jenkinsci-users/7P1Wd2W-OcA

           Hello,

          This is one of the most broadly used feature of the pipeline-maven-plugin, I think it works for most user, there is probably a glitch somewhere.

          Can you please share your testing Jenkinsfile and the details reported by withMaven in the build logs?

          The troubleshooting pipeline script should look like

          withMaven(...) {
             sh "mvn help:effective-settings"
          }
          

          The build logs line that reports the credentials injected in the settings looks like

          [withMaven] using Maven global settings.xml 'global-settings-for-pipeline-maven-plugin' with Maven servers credentials provided by Jenkins (replaceAll: false): [mavenServerId: 'github', jenkinsCredentials: 'github-credentials', username: 'cyrille-leclerc', type: 'UsernamePasswordCredentialsImpl'], [mavenServerId: 'nexus3.example.com', jenkinsCredentials: 'api-team-nexus-deployment-credentials', username: 'api-team', type: 'UsernamePasswordCredentialsImpl']
          

           

          Cyrille Le Clerc added a comment - - edited Cross posting answer already made on  https://groups.google.com/forum/#!topic/jenkinsci-users/7P1Wd2W-OcA  Hello, This is one of the most broadly used feature of the pipeline-maven-plugin, I think it works for most user, there is probably a glitch somewhere. Can you please share your testing Jenkinsfile and the details reported by withMaven in the build logs? The troubleshooting pipeline script should look like withMaven(...) { sh "mvn help:effective-settings" } The build logs line that reports the credentials injected in the settings looks like [withMaven] using Maven global settings.xml 'global-settings- for -pipeline-maven-plugin' with Maven servers credentials provided by Jenkins (replaceAll: false ): [mavenServerId: 'github' , jenkinsCredentials: 'github-credentials' , username: 'cyrille-leclerc' , type: 'UsernamePasswordCredentialsImpl' ], [mavenServerId: 'nexus3.example.com' , jenkinsCredentials: 'api-team-nexus-deployment-credentials' , username: 'api-team' , type: 'UsernamePasswordCredentialsImpl' ]  
          Cyrille Le Clerc made changes -
          Assignee Original: Dominik Bartholdi [ domi ] New: Cyrille Le Clerc [ cleclerc ]

          red der added a comment -

          this can be closed. I gave up and just used a secret file to store my entire config instead. I realized I dont really need this plugin

          red der added a comment - this can be closed. I gave up and just used a secret file to store my entire config instead. I realized I dont really need this plugin

          Ack, i'm closing this ticket with "Can't reproduce" as several users have reported that this feature work for them. There me be an edge case or a glitch in the setup.

          Cyrille Le Clerc added a comment - Ack, i'm closing this ticket with "Can't reproduce" as several users have reported that this feature work for them. There me be an edge case or a glitch in the setup.
          Cyrille Le Clerc made changes -
          Resolution New: Cannot Reproduce [ 5 ]
          Status Original: Open [ 1 ] New: Closed [ 6 ]

          rross added a comment - - edited

          Whelp, I think I'm hitting this same exact "edge case".  I have tried both Global and user settings files, configured under Managed Files.  I've tried setting them as the default under tools configuration, as well as explicitly calling them by id on `withMaven`.  Nothing seems to work at all.  Using the steps to reproduce documented in this ticket, I crafted this stage:

            agent any
          
            tools {
              maven 'Maven_3.6.0'
              jdk 'jdk11'
            }
          
            stages {
              stage('Setup') {
                steps {
                  withMaven {
                    sh 'mvn help:effective-settings'
                  }
                }
              }
            }

          Running gets this in the pipeline log:

          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Debug)
          [Pipeline] tool
          [Pipeline] envVarsForTool
          [Pipeline] tool
          [Pipeline] envVarsForTool
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] withMaven
          [2021-12-16T14:41:48.646Z] [withMaven] Options: []
          [2021-12-16T14:41:48.646Z] [withMaven] Available options: 
          [2021-12-16T14:41:48.646Z] [withMaven] using JDK installation provided by the build agent
          [2021-12-16T14:41:48.652Z] [withMaven] using Maven global settings.xml 'global-maven-settings' with Maven servers credentials provided by Jenkins (replaceAll: false): [mavenServerId: 'com.myinternal.repo.releases', jenkinsCredentials: '7ad2488b-6087-4727-a1ca-6b9ced57baa6', username: 'ci', type: 'UsernamePasswordCredentialsImpl'], [mavenServerId: 'com.myinternal.repo.snapshots', jenkinsCredentials: '7ad2488b-6087-4727-a1ca-6b9ced57baa6', username: 'ci', type: 'UsernamePasswordCredentialsImpl']
          [2021-12-16T14:41:48.653Z] $ /bin/sh -c "which mvn"
          [2021-12-16T14:41:48.660Z] [withMaven] Maven installation not specified in the 'withMaven()' step and not found on the build agent but 'mvnw' script found in the workspace.
          [Pipeline] {
          [Pipeline] sh
          [2021-12-16T14:41:48.954Z] + mvn help:effective-settings
          [2021-12-16T14:41:48.954Z] Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f" 
          [2021-12-16T14:41:51.452Z] [INFO] [jenkins-event-spy] Generate /var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f/maven-spy-20211216-144151-18111412161578554802831.log.tmp ...
          [2021-12-16T14:41:51.706Z] [INFO] Scanning for projects...
          [2021-12-16T14:41:52.257Z] [INFO] 
          [2021-12-16T14:41:52.257Z] [INFO] ------------------< com.myinternal.ncp:log-client-java >-------------------
          [2021-12-16T14:41:52.257Z] [INFO] Building Log Client for Java 1.2.1-SNAPSHOT
          [2021-12-16T14:41:52.257Z] [INFO] --------------------------------[ jar ]---------------------------------
          [2021-12-16T14:41:52.508Z] [INFO] 
          [2021-12-16T14:41:52.508Z] [INFO] --- maven-help-plugin:3.2.0:effective-settings (default-cli) @ log-client-java ---
          [2021-12-16T14:41:53.419Z] [INFO] 
          [2021-12-16T14:41:53.419Z] Effective user-specific configuration settings:
          [2021-12-16T14:41:53.419Z] 
          [2021-12-16T14:41:53.419Z] <?xml version="1.0" encoding="UTF-8"?>
          [2021-12-16T14:41:53.419Z] <!-- ====================================================================== -->
          [2021-12-16T14:41:53.419Z] <!--                                                                        -->
          [2021-12-16T14:41:53.419Z] <!-- Generated by Maven Help Plugin on 2021-12-16T14:41:53Z                 -->
          [2021-12-16T14:41:53.419Z] <!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
          [2021-12-16T14:41:53.419Z] <!--                                                                        -->
          [2021-12-16T14:41:53.419Z] <!-- ====================================================================== -->
          [2021-12-16T14:41:53.420Z] <!-- ====================================================================== -->
          [2021-12-16T14:41:53.420Z] <!--                                                                        -->
          [2021-12-16T14:41:53.420Z] <!-- Effective Settings for 'jenkins' on 'ip-***-***-***-***'               -->
          [2021-12-16T14:41:53.420Z] <!--                                                                        -->
          [2021-12-16T14:41:53.420Z] <!-- ====================================================================== -->
          [2021-12-16T14:41:53.420Z] <settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
          [2021-12-16T14:41:53.420Z]   <localRepository>/var/lib/jenkins/.m2/repository</localRepository>
          [2021-12-16T14:41:53.420Z]   <pluginGroups>
          [2021-12-16T14:41:53.420Z]     <pluginGroup>org.apache.maven.plugins</pluginGroup>
          [2021-12-16T14:41:53.420Z]     <pluginGroup>org.codehaus.mojo</pluginGroup>
          [2021-12-16T14:41:53.420Z]   </pluginGroups>
          [2021-12-16T14:41:53.420Z] </settings>
          

          Absolutely nothing from the referenced "global-maven-settings" is actually in the effective settings when running mvn.  Not a servers section containing the auth data referenced just above in the pipeline logs, and not a single part of my actual settings.xml content which is stored on the managed file:

          <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
          	<activeProfiles>
          		<activeProfile>default</activeProfile>
          	</activeProfiles>
          	<profiles>
          		<profile>
          			<id>default</id>
          			<repositories>
          				<repository>
          					<releases>
          						<enabled>false</enabled>
          					</releases>
          					<snapshots>
          						<enabled>true</enabled>
          					</snapshots>
          					<id>com.myinternal.repo.snapshots</id>
          					<name>Internal Snapshots</name>
          					<url>https://artifact.myinternal.com/repository/maven-snapshots</url>
          				</repository>
          				<repository>
          					<releases>
          						<enabled>true</enabled>
          					</releases>
          					<snapshots>
          						<enabled>false</enabled>
          					</snapshots>
          					<id>com.myinternal.repo.releases</id>
          					<name>Internal Releases</name>
          					<url>https://artifact.myinternal.com/repository/maven-releases</url>
          				</repository>
          			</repositories>
          		</profile>
          	</profiles>
          </settings>
          

          rross added a comment - - edited Whelp, I think I'm hitting this same exact "edge case".  I have tried both Global and user settings files, configured under Managed Files.  I've tried setting them as the default under tools configuration, as well as explicitly calling them by id on `withMaven`.  Nothing seems to work at all.  Using the steps to reproduce documented in this ticket, I crafted this stage: agent any tools { maven 'Maven_3.6.0' jdk 'jdk11' }   stages { stage('Setup') { steps { withMaven { sh 'mvn help:effective-settings' } } } } Running gets this in the pipeline log: [Pipeline] // stage [Pipeline] stage [Pipeline] { (Debug) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] withEnv [Pipeline] { [Pipeline] withMaven [2021-12-16T14:41:48.646Z] [withMaven] Options: [] [2021-12-16T14:41:48.646Z] [withMaven] Available options: [2021-12-16T14:41:48.646Z] [withMaven] using JDK installation provided by the build agent [2021-12-16T14:41:48.652Z] [withMaven] using Maven global settings.xml 'global-maven-settings' with Maven servers credentials provided by Jenkins (replaceAll: false): [mavenServerId: 'com.myinternal.repo.releases', jenkinsCredentials: '7ad2488b-6087-4727-a1ca-6b9ced57baa6', username: 'ci', type: 'UsernamePasswordCredentialsImpl'], [mavenServerId: 'com.myinternal.repo.snapshots', jenkinsCredentials: '7ad2488b-6087-4727-a1ca-6b9ced57baa6', username: 'ci', type: 'UsernamePasswordCredentialsImpl'] [2021-12-16T14:41:48.653Z] $ /bin/sh -c "which mvn" [2021-12-16T14:41:48.660Z] [withMaven] Maven installation not specified in the 'withMaven()' step and not found on the build agent but 'mvnw' script found in the workspace. [Pipeline] { [Pipeline] sh [2021-12-16T14:41:48.954Z] + mvn help:effective-settings [2021-12-16T14:41:48.954Z] Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f" [2021-12-16T14:41:51.452Z] [INFO] [jenkins-event-spy] Generate /var/lib/jenkins/workspace/NL_log-client-java_PR-25@tmp/withMaven1b728b0f/maven-spy-20211216-144151-18111412161578554802831.log.tmp ... [2021-12-16T14:41:51.706Z] [INFO] Scanning for projects... [2021-12-16T14:41:52.257Z] [INFO] [2021-12-16T14:41:52.257Z] [INFO] ------------------< com.myinternal.ncp:log-client-java >------------------- [2021-12-16T14:41:52.257Z] [INFO] Building Log Client for Java 1.2.1-SNAPSHOT [2021-12-16T14:41:52.257Z] [INFO] --------------------------------[ jar ]--------------------------------- [2021-12-16T14:41:52.508Z] [INFO] [2021-12-16T14:41:52.508Z] [INFO] --- maven-help-plugin:3.2.0:effective-settings (default-cli) @ log-client-java --- [2021-12-16T14:41:53.419Z] [INFO] [2021-12-16T14:41:53.419Z] Effective user-specific configuration settings: [2021-12-16T14:41:53.419Z] [2021-12-16T14:41:53.419Z] <?xml version="1.0" encoding="UTF-8"?> [2021-12-16T14:41:53.419Z] <!-- ====================================================================== --> [2021-12-16T14:41:53.419Z] <!-- --> [2021-12-16T14:41:53.419Z] <!-- Generated by Maven Help Plugin on 2021-12-16T14:41:53Z --> [2021-12-16T14:41:53.419Z] <!-- See: http://maven.apache.org/plugins/maven-help-plugin/ --> [2021-12-16T14:41:53.419Z] <!-- --> [2021-12-16T14:41:53.419Z] <!-- ====================================================================== --> [2021-12-16T14:41:53.420Z] <!-- ====================================================================== --> [2021-12-16T14:41:53.420Z] <!-- --> [2021-12-16T14:41:53.420Z] <!-- Effective Settings for 'jenkins' on 'ip-***-***-***-***' --> [2021-12-16T14:41:53.420Z] <!-- --> [2021-12-16T14:41:53.420Z] <!-- ====================================================================== --> [2021-12-16T14:41:53.420Z] <settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"> [2021-12-16T14:41:53.420Z] <localRepository>/var/lib/jenkins/.m2/repository</localRepository> [2021-12-16T14:41:53.420Z] <pluginGroups> [2021-12-16T14:41:53.420Z] <pluginGroup>org.apache.maven.plugins</pluginGroup> [2021-12-16T14:41:53.420Z] <pluginGroup>org.codehaus.mojo</pluginGroup> [2021-12-16T14:41:53.420Z] </pluginGroups> [2021-12-16T14:41:53.420Z] </settings> Absolutely nothing from the referenced "global-maven-settings" is actually in the effective settings when running mvn .  Not a servers section containing the auth data referenced just above in the pipeline logs, and not a single part of my actual settings.xml content which is stored on the managed file: <settings xmlns= "http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd" > <activeProfiles> <activeProfile> default </activeProfile> </activeProfiles> <profiles> <profile> <id> default </id> <repositories> <repository> <releases> <enabled> false </enabled> </releases> <snapshots> <enabled> true </enabled> </snapshots> <id> com.myinternal.repo.snapshots </id> <name> Internal Snapshots </name> <url> https://artifact.myinternal.com/repository/maven-snapshots </url> </repository> <repository> <releases> <enabled> true </enabled> </releases> <snapshots> <enabled> false </enabled> </snapshots> <id> com.myinternal.repo.releases </id> <name> Internal Releases </name> <url> https://artifact.myinternal.com/repository/maven-releases </url> </repository> </repositories> </profile> </profiles> </settings>
          rross made changes -
          Resolution Original: Cannot Reproduce [ 5 ]
          Status Original: Closed [ 6 ] New: Reopened [ 4 ]

            Unassigned Unassigned
            red888 red der
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: