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

API to decorate console output

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: pipeline
    • Labels:
    • Similar Issues:

      Description

      At least within a block step, it should be possible to set something like a ConsoleLogFilter to decorate the output written to TaskListener. Possible use cases:

      • Replacement for decorateLogger in SimpleBuildWrapper.
      • Ability to mask passwords from BindingStep in credentials-binding (unless there is an equivalent to getSensitiveBuildVariables moved up to Run).

        Attachments

          Issue Links

            Activity

            jglick Jesse Glick created issue -
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Link This issue is blocking JENKINS-24673 [ JENKINS-24673 ]
            Hide
            jglick Jesse Glick added a comment - - edited

            Suggested API: reuse ConsoleLogFilter (passing null for the AbstractBuild argument and requiring implementations to be Serializable), where you can pass this in to BodyInvoker.withContexts (first checking for an instance in your own context to delegate to).

            OutputStream SimpleBuildWrapper.decorateLogger(AbstractBuild, OutputStream) could then be made to delegate to a new method ConsoleLogFilter SimpleBuildWrapper.createDecorator(Run<?,?> build) if the API were copied into core, and CoreWrapperStep (PR 37) needs to call that.

            Show
            jglick Jesse Glick added a comment - - edited Suggested API: reuse ConsoleLogFilter (passing null for the AbstractBuild argument and requiring implementations to be Serializable ), where you can pass this in to BodyInvoker.withContexts (first checking for an instance in your own context to delegate to). OutputStream SimpleBuildWrapper.decorateLogger(AbstractBuild, OutputStream) could then be made to delegate to a new method ConsoleLogFilter SimpleBuildWrapper.createDecorator(Run<?,?> build) if the API were copied into core, and CoreWrapperStep (PR 37) needs to call that.
            jglick Jesse Glick made changes -
            Link This issue is blocking JENKINS-27207 [ JENKINS-27207 ]
            Hide
            tfennelly Tom FENNELLY added a comment - - edited

            Just stashing something I experimented with for this last week (before this JIRA was created). Not based on TaskListener, but instead filtering the logs inside a block based on an Action. We'll more than likely throw this away but just wanted to attach in case.

            https://github.com/tfennelly/workflow-plugin/tree/mask-log-entries (link to the branch - press "Compare" etc if you want)

            (totally incomplete and only kinda works)

            Show
            tfennelly Tom FENNELLY added a comment - - edited Just stashing something I experimented with for this last week (before this JIRA was created). Not based on TaskListener, but instead filtering the logs inside a block based on an Action. We'll more than likely throw this away but just wanted to attach in case. https://github.com/tfennelly/workflow-plugin/tree/mask-log-entries (link to the branch - press "Compare" etc if you want) (totally incomplete and only kinda works)
            kohsuke Kohsuke Kawaguchi made changes -
            Link This issue is blocking JENKINS-27486 [ JENKINS-27486 ]
            jglick Jesse Glick made changes -
            Link This issue is related to JENKINS-26053 [ JENKINS-26053 ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Status In Progress [ 3 ] Open [ 1 ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "PR 107 (Web Link)" [ 12203 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            step-api/src/main/java/org/jenkinsci/plugins/workflow/steps/BodyInvoker.java
            support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java
            http://jenkins-ci.org/commit/workflow-plugin/38cd1ea642bd45e45331e89c8cef7ffb8e3740fa
            Log:
            [FIXED JENKINS-27392] Handling ConsoleLogFilter.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: step-api/src/main/java/org/jenkinsci/plugins/workflow/steps/BodyInvoker.java support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java http://jenkins-ci.org/commit/workflow-plugin/38cd1ea642bd45e45331e89c8cef7ffb8e3740fa Log: [FIXED JENKINS-27392] Handling ConsoleLogFilter.
            scm_issue_link SCM/JIRA link daemon made changes -
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Resolved [ 5 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            step-api/src/main/java/org/jenkinsci/plugins/workflow/steps/BodyInvoker.java
            support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java
            http://jenkins-ci.org/commit/workflow-plugin/16eb0143aa3f04e5e89eab55ca60101b98b9b449
            Log:
            Merge pull request #107 from jglick/ConsoleLogFilter-JENKINS-27392

            JENKINS-27392 ConsoleLogFilter

            Compare: https://github.com/jenkinsci/workflow-plugin/compare/d60edde46f20...16eb0143aa3f

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: step-api/src/main/java/org/jenkinsci/plugins/workflow/steps/BodyInvoker.java support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java http://jenkins-ci.org/commit/workflow-plugin/16eb0143aa3f04e5e89eab55ca60101b98b9b449 Log: Merge pull request #107 from jglick/ConsoleLogFilter- JENKINS-27392 JENKINS-27392 ConsoleLogFilter Compare: https://github.com/jenkinsci/workflow-plugin/compare/d60edde46f20...16eb0143aa3f
            jglick Jesse Glick made changes -
            Remote Link This issue links to "Derived PR 1 (Web Link)" [ 12205 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "mask-passwords-plugin PR 3 (Web Link)" [ 12207 ]
            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/e6715815daefaf4be79b3a8d68a7a5fe23b21fba Log: JENKINS-27392 Noting. https://github.com/jenkinsci/mask-passwords-plugin/pull/3
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            core/src/main/java/jenkins/tasks/SimpleBuildWrapper.java
            test/src/test/java/jenkins/tasks/SimpleBuildWrapperTest.java
            http://jenkins-ci.org/commit/jenkins/a52d665180a7b11dcd64673c3f08b719f6c9f908
            Log:
            JENKINS-27392 SimpleBuildWrapper.createLoggerDecorator

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/jenkins/tasks/SimpleBuildWrapper.java test/src/test/java/jenkins/tasks/SimpleBuildWrapperTest.java http://jenkins-ci.org/commit/jenkins/a52d665180a7b11dcd64673c3f08b719f6c9f908 Log: JENKINS-27392 SimpleBuildWrapper.createLoggerDecorator
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            core/src/main/java/jenkins/tasks/SimpleBuildWrapper.java
            test/src/test/java/jenkins/tasks/SimpleBuildWrapperTest.java
            http://jenkins-ci.org/commit/jenkins/61b3fb9483f03bcb614ee43835c21cf39afcdf23
            Log:
            Merge pull request #1634 from jglick/SimpleBuildWrapper-JENKINS-27392

            JENKINS-27392 SimpleBuildWrapper.createLoggerDecorator

            Compare: https://github.com/jenkinsci/jenkins/compare/2020bbd5137d...61b3fb9483f0

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/jenkins/tasks/SimpleBuildWrapper.java test/src/test/java/jenkins/tasks/SimpleBuildWrapperTest.java http://jenkins-ci.org/commit/jenkins/61b3fb9483f03bcb614ee43835c21cf39afcdf23 Log: Merge pull request #1634 from jglick/SimpleBuildWrapper- JENKINS-27392 JENKINS-27392 SimpleBuildWrapper.createLoggerDecorator Compare: https://github.com/jenkinsci/jenkins/compare/2020bbd5137d...61b3fb9483f0
            Hide
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #4059

            Result = SUCCESS

            Show
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #4059 Result = SUCCESS
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
            http://jenkins-ci.org/commit/workflow-plugin/4ad6605229b6f248fa06c8d9be9bd8bcdb547f80
            Log:
            JENKINS-27392 Prepared test for SimpleBuildWrapper.createLoggerDecorator.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java http://jenkins-ci.org/commit/workflow-plugin/4ad6605229b6f248fa06c8d9be9bd8bcdb547f80 Log: JENKINS-27392 Prepared test for SimpleBuildWrapper.createLoggerDecorator.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
            basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java
            pom.xml
            http://jenkins-ci.org/commit/workflow-plugin/874c4618f43316e096562499f0f6a3636951919a
            Log:
            JENKINS-27392 Using SimpleBuildWrapper.createLoggerDecorator from CoreWrapperStep.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java pom.xml http://jenkins-ci.org/commit/workflow-plugin/874c4618f43316e096562499f0f6a3636951919a Log: JENKINS-27392 Using SimpleBuildWrapper.createLoggerDecorator from CoreWrapperStep.
            jglick Jesse Glick made changes -
            Link This issue is related to JENKINS-30777 [ JENKINS-30777 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            pom.xml
            src/main/java/com/michelin/cio/hudson/plugins/maskpasswords/MaskPasswordsBuildWrapper.java
            src/main/java/com/michelin/cio/hudson/plugins/passwordparam/PasswordParameterValue.java
            src/test/java/com/michelin/cio/hudson/plugins/maskpasswords/MaskPasswordsWorkflowTest.java
            http://jenkins-ci.org/commit/mask-passwords-plugin/453e8b54b64ad2b54335b1f4265fd90e33d8bf2e
            Log:
            JENKINS-27392 Implement SimpleBuildWrapper in order to support Workflow project type .

            This pull request integrates https://github.com/jenkinsci/mask-passwords-plugin/pull/3

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/com/michelin/cio/hudson/plugins/maskpasswords/MaskPasswordsBuildWrapper.java src/main/java/com/michelin/cio/hudson/plugins/passwordparam/PasswordParameterValue.java src/test/java/com/michelin/cio/hudson/plugins/maskpasswords/MaskPasswordsWorkflowTest.java http://jenkins-ci.org/commit/mask-passwords-plugin/453e8b54b64ad2b54335b1f4265fd90e33d8bf2e Log: JENKINS-27392 Implement SimpleBuildWrapper in order to support Workflow project type . This pull request integrates https://github.com/jenkinsci/mask-passwords-plugin/pull/3
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            COMPATIBILITY.md
            http://jenkins-ci.org/commit/workflow-plugin/8ae0c5d4c33362e7b82a9a39e10b0073eb17f5a7
            Log:
            JENKINS-27392 - Noting Workflow support in Mask Passwords 2.8

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/8ae0c5d4c33362e7b82a9a39e10b0073eb17f5a7 Log: JENKINS-27392 - Noting Workflow support in Mask Passwords 2.8
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java
            http://jenkins-ci.org/commit/workflow-support-plugin/e3bea833905716718ed37ef55c5eb5298c21ec3f
            Log:
            [FIXED JENKINS-27392] Handling ConsoleLogFilter.
            Originally-Committed-As: 38cd1ea642bd45e45331e89c8cef7ffb8e3740fa

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: support/src/main/java/org/jenkinsci/plugins/workflow/support/DefaultStepContext.java http://jenkins-ci.org/commit/workflow-support-plugin/e3bea833905716718ed37ef55c5eb5298c21ec3f Log: [FIXED JENKINS-27392] Handling ConsoleLogFilter. Originally-Committed-As: 38cd1ea642bd45e45331e89c8cef7ffb8e3740fa
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
            http://jenkins-ci.org/commit/workflow-basic-steps-plugin/16c2ccf3948b2f5e1ad0c0ab72556cc4da070db2
            Log:
            JENKINS-27392 Prepared test for SimpleBuildWrapper.createLoggerDecorator.
            Originally-Committed-As: 4ad6605229b6f248fa06c8d9be9bd8bcdb547f80

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java http://jenkins-ci.org/commit/workflow-basic-steps-plugin/16c2ccf3948b2f5e1ad0c0ab72556cc4da070db2 Log: JENKINS-27392 Prepared test for SimpleBuildWrapper.createLoggerDecorator. Originally-Committed-As: 4ad6605229b6f248fa06c8d9be9bd8bcdb547f80
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
            basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java
            http://jenkins-ci.org/commit/workflow-basic-steps-plugin/60cb60720b2ed1ab64ecaeb72c8c8649dec998b6
            Log:
            JENKINS-27392 Using SimpleBuildWrapper.createLoggerDecorator from CoreWrapperStep.
            Originally-Committed-As: 874c4618f43316e096562499f0f6a3636951919a

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java http://jenkins-ci.org/commit/workflow-basic-steps-plugin/60cb60720b2ed1ab64ecaeb72c8c8649dec998b6 Log: JENKINS-27392 Using SimpleBuildWrapper.createLoggerDecorator from CoreWrapperStep. Originally-Committed-As: 874c4618f43316e096562499f0f6a3636951919a
            Hide
            nels4784 Jeffrey Nelson added a comment - - edited

            I am trying to use this wrapper with the cloudbees workflow/pipeline plugin. Refer to the following code snippet:

            node {
                stage 'Test It'
                
                wrap([$class: 'MaskPasswordsBuildWrapper']) {
                    sh '''if [ "$MARATHON_PASSWORD" -eq "theMarathonPassword" ]; then
                              echo it works!
                           fi'''
                }
            }

            I have a global password setup named: MARATHON_PASSWORD with value: theMarathonPassword. However, running this pipeline job results in output:

            Entering stage Test It
            Proceeding
            [Pipeline] stage (Test It)
            [Pipeline] General Build Wrapper : Start
            [Pipeline] wrap {
            [Pipeline] sh
            [AAA-TestPipeline] Running shell script
            + '[' '' -eq ******** ']'
            /apps/jenkins/slave1/workspace/CWL/AAA-TestPipeline/.jenkins-4173bdf1/script.sh: line 2: [: : integer expression expected
            [Pipeline] } //wrap
            [Pipeline] General Build Wrapper : End
            [Pipeline] } //node
            [Pipeline] Allocate node : End
            [Pipeline] End of Pipeline
            Finished: SUCCESS

            In other words, the masking part is working, but accessing the global passwords is not. Am I missing something, or is this a bug?

            Show
            nels4784 Jeffrey Nelson added a comment - - edited I am trying to use this wrapper with the cloudbees workflow/pipeline plugin. Refer to the following code snippet: node { stage 'Test It' wrap([$class: 'MaskPasswordsBuildWrapper' ]) { sh ''' if [ "$MARATHON_PASSWORD" -eq "theMarathonPassword" ]; then echo it works! fi''' } } I have a global password setup named: MARATHON_PASSWORD with value: theMarathonPassword. However, running this pipeline job results in output: Entering stage Test It Proceeding [Pipeline] stage (Test It) [Pipeline] General Build Wrapper : Start [Pipeline] wrap { [Pipeline] sh [AAA-TestPipeline] Running shell script + '[' '' -eq ******** ' ]' /apps/jenkins/slave1/workspace/CWL/AAA-TestPipeline/.jenkins-4173bdf1/script.sh: line 2: [: : integer expression expected [Pipeline] } //wrap [Pipeline] General Build Wrapper : End [Pipeline] } //node [Pipeline] Allocate node : End [Pipeline] End of Pipeline Finished: SUCCESS In other words, the masking part is working, but accessing the global passwords is not. Am I missing something, or is this a bug?
            Hide
            sag47 Sam Gleske added a comment -

            I encounter the same bug.

            Show
            sag47 Sam Gleske added a comment - I encounter the same bug.
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 161597 ] JNJira + In-Review [ 196812 ]
            abayer Andrew Bayer made changes -
            Component/s pipeline-general [ 21692 ]
            abayer Andrew Bayer made changes -
            Component/s workflow-plugin [ 18820 ]
            Hide
            yz George Yermulnik added a comment -

            Same issue here =(
            Is there a way to access global passwords set with Mask Passwords plugin?

            Show
            yz George Yermulnik added a comment - Same issue here =( Is there a way to access global passwords set with Mask Passwords plugin?
            cstroe Cosmin Stroe made changes -
            Link This issue relates to JENKINS-43814 [ JENKINS-43814 ]

              People

              Assignee:
              jglick Jesse Glick
              Reporter:
              jglick Jesse Glick
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: