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

New aid.txt project search only works if codesonar is running on the jenkins machine.

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • codesonar-plugin
    • None

      New aid.txt project search only works if codesonar is running on the jenkins machine.

      My jenkins server and the codesonar analysis is performed on two different machines.

       

      So the new aid.txt approch does not work.

       

          [JENKINS-67526] New aid.txt project search only works if codesonar is running on the jenkins machine.

          Jens added a comment - - edited

          Workaround:
          Save aid in a file.

                      resultfile = os.path.realpath('CodeSonarAnalyseLog/CodeSonarResult.txt')
                      aidfile = os.path.join(workdir + '.prj_files', 'aid.txt')
                      with open(aidfile, 'r') as f:
                          aid = f.read()
                          with open(resultfile, 'a') as r:
                              r.write(f'{name} {aid}\n')
          

          Then in jenkins pipeline

          // run the codesonar analyze commands ...
          stage('Static Code Results') {
          steps {
          script {
          def filePath = readFile "${WORKSPACE}/CodeSonarResult.txt"
          def lines = filePath.readLines()
          for (line in lines)
          { 
          def result = line.tokenize(' ')
          def project = result.get(0)
          def aid = result.get(1) 
          codesonar aid: "$aid", conditions: [warningCountIncreaseNewOnly(percentage: '5.0')], credentialId: '', hubAddress: '', projectName: "$project", protocol: 'http' }
          
          }
          }
          }
          
          

          Jens added a comment - - edited Workaround: Save aid in a file. resultfile = os.path.realpath( 'CodeSonarAnalyseLog/CodeSonarResult.txt' ) aidfile = os.path.join(workdir + '.prj_files' , 'aid.txt' ) with open (aidfile, 'r' ) as f: aid = f.read() with open (resultfile, 'a' ) as r: r.write(f '{name} {aid}\n' ) Then in jenkins pipeline // run the codesonar analyze commands ... stage( 'Static Code Results' ) { steps { script { def filePath = readFile "${WORKSPACE}/CodeSonarResult.txt" def lines = filePath.readLines() for (line in lines) { def result = line.tokenize( ' ' ) def project = result.get(0) def aid = result.get(1) codesonar aid: "$aid" , conditions: [warningCountIncreaseNewOnly(percentage: '5.0' )], credentialId: '', hubAddress: ' ', projectName: "$project" , protocol: ' http' } } } }

          gt_dbechtold added a comment -

          Thank you for reporting this issue and for posting a proposed work-around.

          I apologize that it has taken so long for someone to respond to this issue.  In general, we recommend that you contact GrammaTech support (https://www.grammatech.com/support) if you have trouble with the plugin.

          We will try to keep a closer eye on these Jira issues in the future, but it is likely that we will still ask you to contact support if the solution to the issue is not obvious.

          We have not yet tested your proposed workaround, but we will be interested to learn the cause and to find an easier solution.

          gt_dbechtold added a comment - Thank you for reporting this issue and for posting a proposed work-around. I apologize that it has taken so long for someone to respond to this issue.  In general, we recommend that you contact GrammaTech support ( https://www.grammatech.com/support) if you have trouble with the plugin. We will try to keep a closer eye on these Jira issues in the future, but it is likely that we will still ask you to contact support if the solution to the issue is not obvious. We have not yet tested your proposed workaround, but we will be interested to learn the cause and to find an easier solution.

          gt_dbechtold added a comment -

          It appears that in this case the CodeSonar analysis project file has been saved to some `workdir` location via a python script.  My guess is that this `workdir` location is not in the Jenkins working directory, so the plugin cannot automatically find it.  The `aid` parameter was added to the plugin in order to work-around cases like this, and it appears that the user has indeed found a work-around which uses the `aid` parameter.

          I think the comment that the "jenkins server and the codesonar analysis is performed on two different machines" is not exactly a correct assessment of the situation.  Rather I think the problem is that the project search is happening in a directory that does not contain the analysis project file, so the project file will not be found.  In terms of the implementation, this is expected behavior, although I recognize that it is not what the user might expect.

          In version 3.3.0, we added a new `projectFile` parameter so that users can tell the CodeSonar plugin exactly where their CodeSonar analysis project file is saved.  If you use this new `projectFile` parameter, you can avoid using the `aid` parameter as long as the CodeSonar plugin is invoked within the context of the same agent as that which performed the analysis.

          I don't think there is anything to fix.  Thank you for proposing a work-around and for documenting this issue.

          gt_dbechtold added a comment - It appears that in this case the CodeSonar analysis project file has been saved to some `workdir` location via a python script.  My guess is that this `workdir` location is not in the Jenkins working directory, so the plugin cannot automatically find it.  The `aid` parameter was added to the plugin in order to work-around cases like this, and it appears that the user has indeed found a work-around which uses the `aid` parameter. I think the comment that the "jenkins server and the codesonar analysis is performed on two different machines" is not exactly a correct assessment of the situation.  Rather I think the problem is that the project search is happening in a directory that does not contain the analysis project file, so the project file will not be found.  In terms of the implementation, this is expected behavior, although I recognize that it is not what the user might expect. In version 3.3.0, we added a new `projectFile` parameter so that users can tell the CodeSonar plugin exactly where their CodeSonar analysis project file is saved.  If you use this new `projectFile` parameter, you can avoid using the `aid` parameter as long as the CodeSonar plugin is invoked within the context of the same agent as that which performed the analysis. I don't think there is anything to fix.  Thank you for proposing a work-around and for documenting this issue.

            gt_dbechtold gt_dbechtold
            jens_lund_jensen Jens
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: