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

jenkins sshagent is not working with parallel staging.

      def hosts=[]
      def TARGETLEVEL="L2"
      def UC_CM_ID="CM"monospaced text

      script
      {
      START_SERVER_LIST2.each
      {
      CURRENT_END_HOST="${it}".trim()
      END_SHORT_HOST="${CURRENT_END_HOST}".substring(0,"${CURRENT_END_HOST}".indexOf("."))
      CREDENTIAL_ID="$TARGETLEVEL""""$UC_CM_ID""""${END_SHORT_HOST}"
      hosts.add("${CREDENTIAL_ID}")

      }
      def servers = START_SERVER_LIST2
      def projectsBuilds = [:]
      for (int j=0; j<=5;j++)
      {
      def currentServer = START_SERVER_LIST2.get(j)
      projectsBuilds[currentServer] = {

      stage(String.format('%s execution', 'Checkout on'+currentServer))
      {

      def TAGNAME="TEST"
      def SOURCE_BRANCH_NAME="main"
      def TARGET_BRANCH_NAME="main"
      def SAVE_FILE_PATH="/tmp"
      def UTILITY_SCRIPT_DIR="/tmp"
      def level_name="L2"
      def user_name="cm"

      CURRENT_END_SERVER="${currentServer}".trim()
      END_SHORT_HOSTNAME="${CURRENT_END_SERVER}".substring(0,"${CURRENT_END_SERVER}".indexOf("."))
      END_CM_USER_CREDENTIAL_ID="$TARGETLEVEL""""$UC_CM_ID""""${END_SHORT_HOSTNAME}"
      echo "END_CM_USER_CREDENTIAL_ID=$END_CM_USER_CREDENTIAL_ID"
      sshagent(credentials: ["${END_CM_USER_CREDENTIAL_ID}""])

      { echo "currentServer=$currentServer" echo "END_SHORT_HOSTNAME=$END_SHORT_HOSTNAME" sh """ echo "$user_name"; echo $full_host_name; #ssh -oStrictHostKeyChecking=no -oBatchMode=yes -oLogLevel=error -oUserKnownHostsFile=/dev/null $user_name@$full_host_name /bin/ksh <<EOF """ }

      }
      }

      }
      echo "Parallel builds"
      print(projectsBuilds)
      parallel projectsBuilds;
      }

      we are creating stages dynamically based on the START_SERVER_LIST2 parameter. Created stages running parallelly except sshagent block. When sshagent starts its execution parallely it runs for only last server of START_SERVER_LIST2 parameter.

      Is sshagent blocks paralllel mechanism?
      how to run sshagent parallely for different servers?
      how to pass different parameter values for sshagent block?

          [JENKINS-67025] jenkins sshagent is not working with parallel staging.

          Pravin created issue -
          Pravin made changes -
          Status Original: To Do [ 10003 ] New: In Progress [ 3 ]
          Pravin made changes -
          Description Original: def hosts=[]
          def TARGETLEVEL="L2"
          def UC_CM_ID="CM"{{monospaced text}}

          script
          {
              START_SERVER_LIST2.each
              {
                   CURRENT_END_HOST="${it}".trim()
          END_SHORT_HOST="${CURRENT_END_HOST}".substring(0,"${CURRENT_END_HOST}".indexOf("."))
                          CREDENTIAL_ID="$TARGETLEVEL"+"_"+"$UC_CM_ID"+"_"+"${END_SHORT_HOST}"
          hosts.add("${CREDENTIAL_ID}")
                 
              }
          def servers = START_SERVER_LIST2
                  def projectsBuilds = [:]
          for (int j=0; j<=5;j++)
          {
             def currentServer = START_SERVER_LIST2.get(j)
          projectsBuilds[currentServer] = {
                                     
          stage(String.format('%s execution', 'Checkout on'+currentServer))
          {
                          
                   def TAGNAME="TEST"
          def SOURCE_BRANCH_NAME="main"
                   def TARGET_BRANCH_NAME="main"
          def SAVE_FILE_PATH="/tmp"
          def UTILITY_SCRIPT_DIR="/tmp"
                   def level_name="L2"
          def user_name="cm"
                                             
                  CURRENT_END_SERVER="${currentServer}".trim()
          END_SHORT_HOSTNAME="${CURRENT_END_SERVER}".substring(0,"${CURRENT_END_SERVER}".indexOf("."))
                                  END_CM_USER_CREDENTIAL_ID="$TARGETLEVEL"+"_"+"$UC_CM_ID"+"_"+"${END_SHORT_HOSTNAME}"
          echo "END_CM_USER_CREDENTIAL_ID=$END_CM_USER_CREDENTIAL_ID"
          sshagent(credentials: ["${END_CM_USER_CREDENTIAL_ID}""])
          {
          echo "currentServer=$currentServer"
          echo "END_SHORT_HOSTNAME=$END_SHORT_HOSTNAME"
          sh """
                   echo "$user_name";
                           echo $full_host_name;
                                   #ssh -oStrictHostKeyChecking=no -oBatchMode=yes -oLogLevel=error -oUserKnownHostsFile=/dev/null $user_name@$full_host_name /bin/ksh <<EOF
          """
          }
          }
          }
                  
            }
          echo "Parallel builds"
          print(projectsBuilds)
          parallel projectsBuilds;
           }

          we are creating stages dynamically based on the START_SERVER_LIST2 parameter. Created stages running parallelly except sshagent block. When sshagent starts its execution parallely it runs for only last server os START_SERVER_LIST2 parameter.

          Is sshagent blocks paralllel mechanism?
          how to run sshagent parallely for different servers?
          how to pass different parameter values for sshagent block?
          New: def hosts=[]
           def TARGETLEVEL="L2"
           def UC_CM_ID="CM"{{monospaced text}}

          script
           {
           START_SERVER_LIST2.each
           {
           CURRENT_END_HOST="${it}".trim()
           END_SHORT_HOST="${CURRENT_END_HOST}".substring(0,"${CURRENT_END_HOST}".indexOf("."))
           CREDENTIAL_ID="$TARGETLEVEL"+"_"_+_"$UC_CM_ID"+"+_""${END_SHORT_HOST}"
           hosts.add("${CREDENTIAL_ID}")

          }
           def servers = START_SERVER_LIST2
           def projectsBuilds = [:]
           for (int j=0; j<=5;j++)
           {
           def currentServer = START_SERVER_LIST2.get(j)
           projectsBuilds[currentServer] = {

          stage(String.format('%s execution', 'Checkout on'+currentServer))
           {

          def TAGNAME="TEST"
           def SOURCE_BRANCH_NAME="main"
           def TARGET_BRANCH_NAME="main"
           def SAVE_FILE_PATH="/tmp"
           def UTILITY_SCRIPT_DIR="/tmp"
           def level_name="L2"
           def user_name="cm"

          CURRENT_END_SERVER="${currentServer}".trim()
           END_SHORT_HOSTNAME="${CURRENT_END_SERVER}".substring(0,"${CURRENT_END_SERVER}".indexOf("."))
           END_CM_USER_CREDENTIAL_ID="$TARGETLEVEL"+"_"_+_"$UC_CM_ID"+"+_""${END_SHORT_HOSTNAME}"
           echo "END_CM_USER_CREDENTIAL_ID=$END_CM_USER_CREDENTIAL_ID"
           sshagent(credentials: ["${END_CM_USER_CREDENTIAL_ID}""])

          { echo "currentServer=$currentServer" echo "END_SHORT_HOSTNAME=$END_SHORT_HOSTNAME" sh """ echo "$user_name"; echo $full_host_name; #ssh -oStrictHostKeyChecking=no -oBatchMode=yes -oLogLevel=error -oUserKnownHostsFile=/dev/null $user_name@$full_host_name /bin/ksh <<EOF """ }

          }
           }

          }
           echo "Parallel builds"
           print(projectsBuilds)
           parallel projectsBuilds;
           }

          we are creating stages dynamically based on the START_SERVER_LIST2 parameter. Created stages running parallelly except sshagent block. When sshagent starts its execution parallely it runs for only last server of START_SERVER_LIST2 parameter.

          Is sshagent blocks paralllel mechanism?
           how to run sshagent parallely for different servers?
           how to pass different parameter values for sshagent block?
          Pravin made changes -
          Summary Original: sshagent is not working with parallel staging in jenkins New: jenkins sshagent is not working with parallel staging.
          Pravin made changes -
          Component/s New: core [ 21434 ]
          Issue Type Original: Task [ 3 ] New: Bug [ 1 ]
          Pravin made changes -
          Status Original: In Progress [ 3 ] New: To Do [ 10003 ]
          Pravin made changes -
          Status Original: To Do [ 10003 ] New: In Review [ 10005 ]
          Zbynek Konecny made changes -
          Component/s New: core [ 15593 ]
          Component/s New: ssh-agent-plugin [ 17509 ]
          Component/s Original: administrative [ 20861 ]
          Component/s Original: content [ 20860 ]
          Component/s Original: core [ 21434 ]
          Key Original: WEBSITE-774 New: JENKINS-67025
          Workflow Original: WEBSITE: Software Development Workflow [ 249004 ] New: JNJira + In-Review [ 251082 ]
          Project Original: Jenkins Website [ 10401 ] New: Jenkins [ 10172 ]

          Alex Earl added a comment -

          What happens if you add 'def' before the END_CM_USER_CREDENTIAL_ID variable?

          Alex Earl added a comment - What happens if you add 'def' before the END_CM_USER_CREDENTIAL_ID variable?

            pravin_kaldoke Pravin
            pravin_kaldoke Pravin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: