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

Propose adding `diff` utility step

    Details

    • Similar Issues:

      Description

      Currently, diffing files requires using OS specific implementations (sh, bat).

      This has the potential of triggering security approval, which can be an inconvenience.

      Proposing add new `diff` utility step, to allow OS agnostic use in PIpeline jobs.

        Attachments

          Issue Links

            Activity

            Hide
            rndgstn Ron Dagostino added a comment -

            Thanks. The below script does not work for me (I still get "new java.io.File java.lang.String Approving this signature may introduce a security vulnerability! You are advised to deny it."), and I am not running the latest workflow plugin, so it looks like I will have to upgrade to a newer core to get the fix from https://issues.jenkins-ci.org/browse/JENKINS-34650. I agree that adding a diff script is a relatively easy thing to do when that fix is applied, and the script could be shared at https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples as you suggest.

            String call (String path)

            { getFilePathNonCPS(path) }

            @NonCPS
            String getFilePathNonCPS(String path)

            { new java.io.File(path).getAbsolutePath() }

            this

            Show
            rndgstn Ron Dagostino added a comment - Thanks. The below script does not work for me (I still get "new java.io.File java.lang.String Approving this signature may introduce a security vulnerability! You are advised to deny it."), and I am not running the latest workflow plugin, so it looks like I will have to upgrade to a newer core to get the fix from https://issues.jenkins-ci.org/browse/JENKINS-34650 . I agree that adding a diff script is a relatively easy thing to do when that fix is applied, and the script could be shared at https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples as you suggest. String call (String path) { getFilePathNonCPS(path) } @NonCPS String getFilePathNonCPS(String path) { new java.io.File(path).getAbsolutePath() } this
            Hide
            hrmpw Patrick Wolf added a comment -

            I apologize. I didn't think about the context before Ron Dagostino. What you are trying to do won't work anyway.

            A java.io.File works on the local filesystem but most times you will want to diff two files in your workspace. Pipeline executes on the master in a flyweight executor so java.io.File has a context of the master - hence the security exception.

            What you want is this: http://javadoc.jenkins-ci.org/hudson/FilePath.html

            The best working example would be the readFile step: https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/steps/ReadFileStep.java

            This takes a hudson.FilePath and streams it. If you wanted to do a diff it would be very similar but take two file parameters and compare them.

            Show
            hrmpw Patrick Wolf added a comment - I apologize. I didn't think about the context before Ron Dagostino . What you are trying to do won't work anyway. A java.io.File works on the local filesystem but most times you will want to diff two files in your workspace. Pipeline executes on the master in a flyweight executor so java.io.File has a context of the master - hence the security exception. What you want is this: http://javadoc.jenkins-ci.org/hudson/FilePath.html The best working example would be the readFile step: https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/steps/ReadFileStep.java This takes a hudson.FilePath and streams it. If you wanted to do a diff it would be very similar but take two file parameters and compare them.
            Hide
            michaelneale Michael Neale added a comment - - edited

            I understand the platform agnostic angle, but "This has the potential of triggering security approval, which can be an inconvenience." - I don't see how this is the case if you are doing the diff inside sh or bat?

            In terms of a diff step - I assume you mean it takes 3 params: 2 input files, and an output file? or would it take 2 strings and produce a string? or some combination?

            Show
            michaelneale Michael Neale added a comment - - edited I understand the platform agnostic angle, but "This has the potential of triggering security approval, which can be an inconvenience." - I don't see how this is the case if you are doing the diff inside sh or bat? In terms of a diff step - I assume you mean it takes 3 params: 2 input files, and an output file? or would it take 2 strings and produce a string? or some combination?
            Hide
            rndgstn Ron Dagostino added a comment -

            Thanks, Patrick Wolf, for the FilePath vs. FIle info. I have also confirmed that the shared global library code is trusted implicitly in recent versions as per https://issues.jenkins-ci.org/browse/JENKINS-34650, so yes, it would be possible to simply write the script and share it at https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples. I will do so if I end up writing it.

            Michael Neale, I am personally interested in a simple "are two files the same?" step, not full diff functionality.

            Show
            rndgstn Ron Dagostino added a comment - Thanks, Patrick Wolf , for the FilePath vs. FIle info. I have also confirmed that the shared global library code is trusted implicitly in recent versions as per https://issues.jenkins-ci.org/browse/JENKINS-34650 , so yes, it would be possible to simply write the script and share it at https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples . I will do so if I end up writing it. Michael Neale , I am personally interested in a simple "are two files the same?" step, not full diff functionality.
            Hide
            michaelneale Michael Neale added a comment -

            Ron Dagostino right - well that would be far easier to do as a step I think, or global var lib.

            Show
            michaelneale Michael Neale added a comment - Ron Dagostino right - well that would be far easier to do as a step I think, or global var lib.

              People

              • Assignee:
                rsandell rsandell
                Reporter:
                owood Owen Wood
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: