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

Please add the improvement and fix I already did. For using node properties env vars in the plugin.

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • scp-plugin
    • None

    Description

      First I fixed the recursive mkdirs bug that was reported for this scp plugin.
      With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
      The improvement:
      I had the need to be able to use the node properties env vars in the plugin .
      So for example we needed to build the same project on a different hardware and OS.
      Like Solaris SPARC, AIX, HPUX, Windows and so on.
      So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
      Those environment variables we needed to use in the plugin so we can know which project was build successful or failed or any
      other problems.
      Here is the code changes I made to work as I needed:
      The changes was only in class
      be/certipost/hudson/plugin/SCPRepositoryPublisher.java

      I added a method:
      /**

      • Returns the environment variables set for a node/slave. So you can use
      • them, as are in your environment
      • @param envVars
      • @return
        */
        public static EnvVars getEnvVars() {
        Node node = Computer.currentComputer().getNode();
        DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
        .getNodeProperties();

      if (Computer.currentComputer() instanceof MasterComputer)

      { Hudson instance = Hudson.getInstance(); nodeProperties=instance.getGlobalNodeProperties(); }

      Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
      while (iterator.hasNext()) {
      NodeProperty<?> next = iterator.next();
      if (next instanceof EnvironmentVariablesNodeProperty)

      { EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next; EnvVars envVars = envVarProp.getEnvVars(); return envVars; }

      }
      return null;
      }

      and changed the method perform :

      public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
      .........................
      .........................

      Map<String, String> envVars = build.getEnvVars();
      // Patched for env vars
      EnvVars objNodeEnvVars = getEnvVars();
      if (objNodeEnvVars != null)

      { envVars.putAll(objNodeEnvVars); }

      //~ Patched for env vars

      for (Entry e : entries) {
      String expanded = Util.replaceMacro(e.sourceFile, envVars);
      FilePath ws = build.getProject().getWorkspace();
      FilePath[] src = ws.list(expanded);
      if (src.length == 0)

      { // try to do error diagnostics log(listener.getLogger(), ("No file(s) found: " + expanded)); String error = ws.validateAntFileMask(expanded); if (error != null) log(listener.getLogger(), error); }

      String folderPath = Util.replaceMacro(e.filePath, envVars);

      // Fix for recursive mkdirs
      String strWorkspacePath = ws.toString();
      envVars.put("strWorkspacePath", strWorkspacePath);
      // ~Fix for recursive mkdirs

      I also changed the class be/certipost/hudson/plugin/SCPSite.java

      I added the method extractRelativePath:

      /**

      • Returns the relative path to the workspace
      • @param strWorkspacePath
      • @param filePath
      • @return
        */
        private String extractRelativePath(String strWorkspacePath, FilePath filePath)
        Unknown macro: { String strRet=""; String strFilePath=filePath.toString(); if(strWorkspacePath.length() == strFilePath.length()) { return ""; } int indexOf = strFilePath.indexOf(strWorkspacePath); if(indexOf>=0) { strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator } indexOf = strRet.lastIndexOf(File.separator); if(indexOf>0) { strRet=strRet.substring(0,indexOf); } strRet=strRet.replace((CharSequence) "\", (CharSequence)"/"); return strRet; }

      I changed the upload method to became:

      public void upload(String folderPath, FilePath filePath,
      Map<String, String> envVars, PrintStream logger)
      throws IOException, InterruptedException, SftpException {
      if (session == null || channel == null)

      { throw new IOException("Connection to " + hostname + ", user=" + username + " is not established"); }

      SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
      if (rootdirstat == null)

      { throw new IOException( "Can't get stat of root repository directory:" + rootRepositoryPath); }

      else {
      if (!rootdirstat.isDir())

      { throw new IOException(rootRepositoryPath + " is not a directory"); }

      }
      if (filePath.isDirectory()) {
      FilePath[] subfiles = filePath.list("*/");
      if (subfiles != null) {
      for (int i = 0; i < subfiles.length; i++)

      { upload(folderPath + "/" + filePath.getName(), subfiles[i], envVars, logger); }

      }
      } else {
      String strWorkspacePath = envVars.get("strWorkspacePath");
      String localfilename = filePath.getName();
      mkdirs(folderPath, logger);
      InputStream in = filePath.read();
      String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
      String strTmp = folderPath + "/" +strRelativePath;
      String strNewPath = rootRepositoryPath + "/" + strTmp;
      if(!strRelativePath.equals(""))

      { strNewPath += "/"; }

      String strNewFilename = strNewPath + localfilename;
      channel.put(in, strNewFilename);
      in.close();
      }
      }

      Attachments

        Issue Links

          Activity

            Attached zip file has both fixed java files and the original but formatted with my Eclipse - for convenient diff for you.

            So there was many problems with that plug-in.
            In multiconfiguration project:
            The Hudson seems to execute each plug-in in separated threads for each slave and master, but uses the same instances and execution is on the master with context of the slave.
            Also I fixed strange problems under Linux/Unix.

            The first my comment is not good to be placed in the plug-in.
            Please use the attached files in NEW.zip.

            kostakostadinov kostakostadinov added a comment - Attached zip file has both fixed java files and the original but formatted with my Eclipse - for convenient diff for you. So there was many problems with that plug-in. In multiconfiguration project: The Hudson seems to execute each plug-in in separated threads for each slave and master, but uses the same instances and execution is on the master with context of the slave. Also I fixed strange problems under Linux/Unix. The first my comment is not good to be placed in the plug-in. Please use the attached files in NEW.zip.
            ramazanyich2 ramazanyich2 added a comment -

            I committed your changes. Please check it and let me know, I will release it then.

            ramazanyich2 ramazanyich2 added a comment - I committed your changes. Please check it and let me know, I will release it then.

            Code changed in hudson
            User: : ramazanyich2
            Path:
            trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPRepositoryPublisher.java
            trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPSite.java
            http://jenkins-ci.org/commit/27692
            Log:
            JENKINS-5467 fix for recursive mkdirs. introduction of node properties env vars

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : ramazanyich2 Path: trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPRepositoryPublisher.java trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPSite.java http://jenkins-ci.org/commit/27692 Log: JENKINS-5467 fix for recursive mkdirs. introduction of node properties env vars
            mindless Alan Harder added a comment -

            should this issue be marked as resolved?

            mindless Alan Harder added a comment - should this issue be marked as resolved?
            ramazanyich2 ramazanyich2 added a comment -

            as no comments given I suggest we mark it as resolved

            ramazanyich2 ramazanyich2 added a comment - as no comments given I suggest we mark it as resolved
            fransflippo fransflippo added a comment - - edited

            Is this fix backwards compatible? Or can the former behavior still be achieved? Right now scp-ing a/b/c.zip to an scp repository will create directory structure a/b/ even though this may not be desirable.

            EDIT: spoke too soon. This is handled by related issue JENKINS-8170.

            fransflippo fransflippo added a comment - - edited Is this fix backwards compatible? Or can the former behavior still be achieved? Right now scp-ing a/b/c.zip to an scp repository will create directory structure a/b/ even though this may not be desirable. EDIT: spoke too soon. This is handled by related issue JENKINS-8170 .

            People

              ramazanyich2 ramazanyich2
              kostakostadinov kostakostadinov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: