Skip to main content

Cloudbees Jenkins on Kubernettes Maven Integration

Comments

7 comments

  • Denys Digtiar

    Once you create a Team Master or Managed Master. The Config File Provider plugin can be used on this master to define the configs, which then can be consumed by other plugins like for example Pipeline Maven Plugin

    1
  • Nand Venegalla

    The config file provider plugin works only if you have settings.xml but if you plan to use settings-security.xml seems like there is no way to do that.

    0
  • Arnaud Héritier

    Using the settings-security.xml and the maven encryption is less interesting if you just inject the server entries in the settings.xml using credentials? The config is created the time of the build and deleted after.

    0
  • Ashley Giles

    i am trying to use jenkins scripted pipeline to invoke this config file provider plugin along with fetching credentials from jenkins for the username and password, but the below doesn't seem to work.

    stage('Deploy'){
      withCredentials([usernamePassword(credentialsId: 'xyz', passwordVariable: 'Password', usernameVariable: 'Username')])
      {
       
      configFileProvider(
      [configFile(fileId: 'abcde', variable: 'MAVEN_SETTINGS')])
      {
      sh "'${mvnHome}/bin/mvn' -s $MAVEN_SETTINGS deploy -Dserver.username=${env.Username} -Dserver.password=${env.Password}"
      }
      }
     

    }

    where server.username are defined as properties under settings.xml server section for username and password.

    It doesn't even work with :-

    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'xyz', usernameVariable: 'Username', passwordVariable: 'Password'

    Could you please advise how to resolve this?

    0
  • Arnaud Héritier

    It will be easier to use the Maven Pipeline plugin : https://plugins.jenkins.io/pipeline-maven

    node{
      stage ('Build') {
    
        git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'
    
        withMaven(
            // Maven installation declared in the Jenkins "Global Tool Configuration"
            maven: 'M3',
            // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
            // Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
            mavenSettingsConfig: 'my-maven-settings',
            mavenLocalRepo: '.repository') {
    
          // Run the maven build
          sh "mvn clean install"
    
        } // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
      }
    }

     

    For the credentials you are configuring them where you define the configuration file in the config file provider side

    https://plugins.jenkins.io/config-file-provider

     

     

     

     

    0
  • Ashley Giles

    We have to somehow invoke credentials in the scripted JenkinsFile ( scripted and not declarative) from Jenkins Credentials and since we host maven settings.xml, on cloudbess Jenkins using config file provider plugin, so any mvn commands in the pipeline script require us to declare ConfigFileProvider section and that when coupled with withCredentials to pull credentials from Jenkins and store them under variables so that those could be added as maven arguments for build or deploy, etc, just doesn’t work. May be the syntax is incorrect or there is no proper documentation on how to use credentials from Jenkins in a scripted pipeline( works well in declarative pipeline though)
    Any thoughts/suggestions??

    0
  • Ashley Giles

    This has been resolved using :-

    stage('Deploy'){
      def usernameLocal, passwordLocal
      withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'xyz', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME']]) {
      usernameLocal = env.USERNAME
      passwordLocal = env.PASSWORD
      configFileProvider(
      [configFile(fileId: '**********', variable: 'MAVEN_SETTINGS')])
      {
      sh "'${mvnHome}/bin/mvn' -s $MAVEN_SETTINGS deploy -Dserver.username='${usernameLocal}' -Dserver.password='${passwordLocal}'"
      }
      }
      }
    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.