curl 的响应是从 CircleCI 上的 gradle 调用的空蜂
Response for curl is empty beeing called from gradle on CircleCI
我在 gradle 中有一项任务是下载 android APP
的翻译
task('downloadTranslations') {
ext.downloadPOTranslation = { stringsFile, projectId, lang ->
def f = new File(stringsFile)
if (f.exists()) {
println("Delete file: " + f.absolutePath)
f.delete()
}
println("Get lang: " + lang + " for project: " + projectId)
def requestArray = ['curl', '-X', 'POST', "\"https://api.poeditor.com/v2/projects/export\"",
'-d', 'api_token=\"{API_KEY}\"',
'-d', 'id=\"' + projectId + '\"',
'-d', 'language=\"' + lang + '\"',
'-d', 'type=\"android_strings\"']
println(requestArray)
def request = requestArray.execute()
request.waitFor()
def response = request.text
if (response.isEmpty()) {
def errorResponse = request.err.text
println("Error response from server:")
println(errorResponse)
} else {
println("Response from server:")
println(response)
}
...
}
doLast {
downloadPOTranslation("src/main/res/values/strings.xml", "projectNumber", "en-gb")
}
}
当我从本地计算机通过 CLI 或 Android Studio 调用此任务时,一切正常:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]
Response from server:
{"response":{"status":"success","code":"200","message":"OK"},"result":{"url":"https:\/\/api.poeditor.com\/v2\/download\/file\/FILENUMBER"}}
但是当我在 CircleCI 上尝试完全相同时,我得到了一个错误:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]
FAILURE: Build failed with an exception.
* Where:
Build file '/home/circleci/code/app/build.gradle' line: 204
* What went wrong:
Execution failed for task ':app:downloadTranslations'.
> java.io.IOException: Stream closed
流关闭是因为 response.isEmpty()
是 true
并且 request.err
已关闭。
那么 为什么 Gradle 从服务器获取空响应,同时在本地工作?
我也试过 SSH 到 CircleCI 和 运行 直接从 CLI 卷曲 - 响应不为空。
'
和 "
之间的问题不同。
我不知道为什么,但可能 'curl'
被忽略了。
所以
def requestArray = ["curl",
"-X", "POST",
"-d","api_token=API_KEY",
"-d", "id=" + projectId + "",
"-d", "language=" + lang + "",
"-d", "type=android_strings",
"https://api.poeditor.com/v2/projects/export",]
工作正常。
我在 gradle 中有一项任务是下载 android APP
的翻译task('downloadTranslations') {
ext.downloadPOTranslation = { stringsFile, projectId, lang ->
def f = new File(stringsFile)
if (f.exists()) {
println("Delete file: " + f.absolutePath)
f.delete()
}
println("Get lang: " + lang + " for project: " + projectId)
def requestArray = ['curl', '-X', 'POST', "\"https://api.poeditor.com/v2/projects/export\"",
'-d', 'api_token=\"{API_KEY}\"',
'-d', 'id=\"' + projectId + '\"',
'-d', 'language=\"' + lang + '\"',
'-d', 'type=\"android_strings\"']
println(requestArray)
def request = requestArray.execute()
request.waitFor()
def response = request.text
if (response.isEmpty()) {
def errorResponse = request.err.text
println("Error response from server:")
println(errorResponse)
} else {
println("Response from server:")
println(response)
}
...
}
doLast {
downloadPOTranslation("src/main/res/values/strings.xml", "projectNumber", "en-gb")
}
}
当我从本地计算机通过 CLI 或 Android Studio 调用此任务时,一切正常:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]
Response from server:
{"response":{"status":"success","code":"200","message":"OK"},"result":{"url":"https:\/\/api.poeditor.com\/v2\/download\/file\/FILENUMBER"}}
但是当我在 CircleCI 上尝试完全相同时,我得到了一个错误:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]
FAILURE: Build failed with an exception.
* Where:
Build file '/home/circleci/code/app/build.gradle' line: 204
* What went wrong:
Execution failed for task ':app:downloadTranslations'.
> java.io.IOException: Stream closed
流关闭是因为 response.isEmpty()
是 true
并且 request.err
已关闭。
那么 为什么 Gradle 从服务器获取空响应,同时在本地工作?
我也试过 SSH 到 CircleCI 和 运行 直接从 CLI 卷曲 - 响应不为空。
'
和 "
之间的问题不同。
我不知道为什么,但可能 'curl'
被忽略了。
所以
def requestArray = ["curl",
"-X", "POST",
"-d","api_token=API_KEY",
"-d", "id=" + projectId + "",
"-d", "language=" + lang + "",
"-d", "type=android_strings",
"https://api.poeditor.com/v2/projects/export",]
工作正常。