簡體   English   中英

如何運行從 Gradle 任務遠程托管的 shell 腳本

[英]How to run a shell script hosted remotely from a Gradle task

假設你有一個簡單的 bash 腳本

echo $@

將其托管在公共存儲庫中,以便您可以訪問原始文件,例如

https://raw.githubusercontent.com/.../test.sh

然后你可以在 shell 中運行它

bash <(curl -s https://raw.githubusercontent.com/.../test.sh) "hello"

我希望能夠在 gradle 任務中實現這一點。 我試過了:

task testScript(type: Exec) {
  workingDir projectDir
  executable "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) 'hello'"
}

task testScript(type: Exec) {
  workingDir projectDir
  executable "bash"
  args "<(curl -s https://raw.githubusercontent.com/.../test.sh)" 'hello'
}

task testScript(type: Exec) {
  workingDir projectDir
  commandLine "bash", "<(curl -s https://raw.githubusercontent.com/.../test.sh)", "hello"
}

無濟於事。 我究竟做錯了什么?

在您的原始命令中, <(curl -s https://raw.githubusercontent.com/.../test.sh)不是由您調用的bash命令解析的,而是由您調用它的 shell 解析的,正在執行的實際命令類似於bash /dev/fd/63 "hello"

Gradle 不是 shell,只會使用字符串"<(curl -s https://raw.githubusercontent.com/.../test.sh)"作為參數調用bash ,無需進一步處理。

您需要找到一個不需要被調用它的 shell 擴展的命令。 例如,將當前命令作為純文本處理並使用另一個 shell 來解析它:

bash -c 'bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello'

總之,我認為以下應該有效:

task testScript(type: Exec) {
  workingDir projectDir
  executable "bash"
  args "-c", "bash <(curl -s https://raw.githubusercontent.com/.../test.sh) hello"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM