jenkinsci / jenkinsci/workflow-basic-steps-plugin

[JENKINS-62657] Shell steps swallow ticks(') and quotes(") that are escaped

Đang mở
#511 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
component:workflow-basic-steps-plugin imported-jira-issue priority:minor resolution:unresolved
Ngôn ngữ chính
Java
Star
73
Fork
129
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I have an issue where I was trying to run a ssh command inside of a shell step but could not preserve the ticks and quotes I needed in the command I run during the SSH. The command looked something like this:

```

sh "ssh -i $keyFile $adminUser@$Host 'sudo $command -f ${Cloud} -u ${env.USERNAME} -x ${env.PASSWORD} -s \"mountPoint=\'/admintool/1\'\" -p redeploy'"

```

The issue is that the shell script I am running $command requires that mountPoint variable to be within quotes " and the argument after the equals needs to be in ticks '.

This issue only happens on shell steps as I can echo the command correctly by replacing the above sh with echo.

Workaround: In the end I had to build a shell script on disk and just run that so something in the groovy interpretation is breaking things.

Steps to reproduce:

1. Start up a brand new Jenkins instance with Pipeline installed

2. Create a new job with the following definition:

node(){

echo """
ssh -i $PEM_KEY $USER@$MACHINE 'echo "-f Cloud -u USERNAME -x PASSWORD -s \"mountPoint=\'/admintool/1\'\" -p redeploy"'
"""

sh """
ssh -i $PEM_KEY $USER@$MACHINE 'echo "-f Cloud -u USERNAME -x PASSWORD -s \"mountPoint=\'/admintool/1\'\" -p redeploy"'
"""
}

3. Observe that the echo prints out the statememt correctly with: `"mountPoint='/admintool/1'" but the ssh command echo does not as it removes the single ticks around admintool

Thoughts:

My understanding of echo is that it is almost the same as `sh` so I am not sure why the shell step is removing the escaped characters. Maybe there is some interpretation done on `sh` I am not aware of. So if there is any way to fix this or a better workaround I am all ears

---
Originally reported by ataylor, imported from: Shell steps swallow ticks(') and quotes(") that are escaped


  • status: Open
  • priority: Minor
  • component(s): workflow-basic-steps-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 2
  • imported: 20251215-220547

Raw content of original issue

I have an issue where I was trying to run a ssh command inside of a shell step but could not preserve the ticks and quotes I needed in the command I run during the SSH. The command looked something like this:

```
sh "ssh -i $keyFile $adminUser@$Host 'sudo $command -f ${Cloud} -u ${env.USERNAME} -x ${env.PASSWORD} -s \"mountPoint=\'/admintool/1\'\" -p redeploy'"
```

The issue is that the shell script I am running $command requires that mountPoint variable to be within quotes " and the argument after the equals needs to be in ticks '.

This issue only happens on shell steps as I can echo the command correctly by replacing the above sh with echo.

Workaround: In the end I had to build a shell script on disk and just run that so something in the groovy interpretation is breaking things.

Steps to reproduce:
1. Start up a brand new Jenkins instance with Pipeline installed
2. Create a new job with the following definition:


node(){

echo """
ssh -i $PEM_KEY $USER@$MACHINE 'echo "-f Cloud -u USERNAME -x PASSWORD -s \"mountPoint=\'/admintool/1\'\" -p redeploy"'
"""

sh """
ssh -i $PEM_KEY $USER@$MACHINE 'echo "-f Cloud -u USERNAME -x PASSWORD -s \"mountPoint=\'/admintool/1\'\" -p redeploy"'
"""
}


3. Observe that the echo prints out the statememt correctly with: `"mountPoint='/admintool/1'" but the ssh command echo does not as it removes the single ticks around admintool

Thoughts:
My understanding of echo is that it is almost the same as `sh` so I am not sure why the shell step is removing the escaped characters. Maybe there is some interpretation done on `sh` I am not aware of. So if there is any way to fix this or a better workaround I am all ears

  • environment: Jenkins version 2.138.1 but has been tested against the latest LTS and still happens

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu từ bước sh của Pipeline và tái hiện lệnh SSH được đặt trong dấu ngoặc kép, đồng thời so sánh lệnh đó với bước echo. Theo dõi cách bước shell xử lý các dấu ngoặc đơn và dấu ngoặc kép được escape, sau đó xác minh hành vi bằng một kiểm tra hồi quy; hoàn thành khi lệnh SSH giữ nguyên cách đặt dấu ngoặc được echo hiển thị.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, shell
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.