opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
72 stars 57 forks source link

Avoid Groovy string interpolation #1042

Closed serverhorror closed 11 months ago

serverhorror commented 11 months ago

fixes Insecure bash secret usage in bash script #1030

fix #1030

serverhorror commented 11 months ago

Not sure how to test this, if anyone has a project where this can be tested easily that is of great help

@braisvq1996

serverhorror commented 11 months ago

For reference, this is based on the suggestions in here:

BraisVQ commented 11 months ago

Not sure how to test this, if anyone has a project where this can be tested easily that is of great help

@braisvq1996

This happens in Component pipeline so it should be fairly easy to test

BraisVQ commented 11 months ago

Something does not seem right, now I am getting error 401

BraisVQ commented 11 months ago

Following Jenkins documentation I was not able to avoid String Interpolation in any way. The only way I was able to is like this:

script.sh(
    label: 'Create Bitbucket Code Insight report via API',
    script: "curl " +
        "--fail " +
        "-sS " +
        "--request PUT " +
        "--header 'Authorization: Bearer ${token}' " +
        "--header 'Content-Type: application/json' " +
        "--data '${payload}' " +
        "${bitbucketUrl}/rest/insights/1.0/projects/${project}/\
repos/${repo}/commits/${gitCommit}/reports/${data.key}"
        )
serverhorror commented 11 months ago

String in the code:

        "--header 'Authorization: Bearer \${token}' " +
                                             // ^^^

That should have made Groovy avoid string interpolation and pass it to the shell.

Is it just component pipeline with any component?

serverhorror commented 11 months ago

@braisvq1996 I think I got it.

image

serverhorror commented 11 months ago

fix #1030