Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

Jenkins Pipeline - String parameter creates a new line even after trim()

I am trying to use string parameter but it is always creating new line even when I am using trim() I followed solution from Jenkins Pipeline - inserting variable in shell creates a new line

Pipeline Code

    parameters {
        string(defaultValue: '', description: 'url', name: 'Url')
    }
    environment {
        KEY = credentials('KEY')
        USERNAME = credentials('USERNAME')
        PASSWORD = credentials('PASSWORD')
        //Parameters
        URL = "${params.Url.trim()}"
    }
    stage('Run script to upload image') {
            steps {
                script {
                        sh '''
                            if [ -n "${URL}" ]; then
                                ./create_and_upload_image.sh --url ${URL} --uname ${USERNAME} --password ${PASSWORD} --key ${KEY}"
                            fi
                          //More steps
                        '''
                }
             }
       }                     

Output

+ [ -n 
https://access.cdn.com/content/origin/files/sha256/4e/4e5c7cccb5ea7622640c97725912222458af743cf994e48f10239734c6a2ee65/image.qcow2 ]
+ ./create_and_upload_image.sh --url 
https://access.cdn.com/content/origin/files/sha256/4e/4e5c7cccb5ea7622640c97725912222458af743cf994e48f10239734c6a2ee65/image.qcow2 --uname **** --password **** --key ****
bash: --uname: command not found

What should I do to avoid new line


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...