如何将环境变量URL字符串传递到Jenkins中的Gradle任务?

rslzwgfq  于 11个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(126)

**问题:*如何将环境变量传递给Jenkins中的gradle任务?需要“ 我的Jenkins作业如何工作 *”中的步骤3的帮助
我做过的研究:

How Do I Set Environment Variable In Gradle via Task?
Passing Command Line Arguments in Gradle
Pass job parameter to gradle task in scripted pipeline

我的Jenkins工作如何运作:

1.我有一个参数,允许文件上传到个人云存储
1.然后,它返回一个URL链接,指向云存储中的这个特定文件,并存储在一个环境变量中:APK_URL
2)示例链接:https://my-storage.com/5/fileVersion/12345.apk

output=$(curl -F file=@"$WORKSPACE/build/SomeProject" -H "Retention: $RETENTION_DAYS" [https://www.myCloudServer.online/fileuploader?key=$MY_KEY](https://www.myCloudServer.online/fileuploader?key=$MY_KEY))
APK_URL=$(echo "$output" | sed -n 's/.*"file_url":"\([^"]*\)".*/\1/p' | sed 's/\\//g')
echo "APK URL": ${env.APK_URL}"

字符串
1.然后APK_URL变量被传递给一个gradle命令,该命令接受一个url字符串来运行我的自动化操作。-DbuildUrl=${env.APK.URL}只是为了说明,当我在本地执行此操作时,这是有效的,所以我知道在这里传递一个URL是有效的。我只是想在Jenkins中完成同样的事情。

clean test --tests "appium.some.app.Tests.*"  -DincludeTags=$RUN_TYPE -DwebhookUrl=[https://hooks.slack.com/services/someSlackChannel](https://hooks.slack.com/services/someSlackChannel) -DbuildUrl=${env.APK_URL}


1.自动化开始

Jenkins配置


的数据

错误日志

  • 我已经改变了一些错误的读取方式,例如URL和任何其他敏感信息
15:11:29 Copying file to build/SomeAppFile
15:11:34 [verify-android] $ /bin/sh -xe /tmp/jenkins84982492834209384.sh
15:11:34 + curl -F file=@/home/jenkins/workspace/my-workSpace/validate/verify-android/build/SomeAppFile -H Retention:  https://www.myCloudStorage.online/f1euploader?key=[***********]
15:11:34   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
15:11:34                                  Dload  Upload   Total   Spent    Left  Speed
15:11:37
15:11:37 + output={"file_url":"https:\/\/www.myCloudStorage.online\/11\//SomeApplicationFile","retention_days":11,"release_pending":false,"results":"success","time_of_release":-1}
15:11:37 + echo {"file_url":"https:\/\/www.myCloudStorage.online\/11\//SomeApplicationFile","retention_days":11,"release_pending":false,"results":"success","time_of_release":-1}
15:11:37 + sed -n s/.*"file_url":"\([^"]*\)".*/\1/p
15:11:37 + sed s/\\//g
15:11:37 + APK_URL=https://www.myCloudStorage.online/11/SomeApplicationFile
15:11:37 + echo https://www.myCloudStorage.online/11/SomeApplicationFile
15:11:37 https://www.myCloudStorage.online/11/SomeApplicationFile
15:11:37 [Gradle] - Launching build.
15:11:37 [qae-verify-android-build] $ "/home/jenkins/workspace/my-workspace/validate/verify-android/gradlew" clean test --tests com.some.app.TESTS.* -DincludeTags=smoke -DwebhookUrl=https://hook.slack.com/services/98asdf9a87fg9a87fg9a87fga989f98 -DbuildUrl=${env.APK_URL}
15:11:38 Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
15:11:44 > Task :clean
15:11:44 > Task :compileJava NO-SOURCE
15:11:44 > Task :processResources NO-SOURCE
15:11:44 > Task :classes UP-TO-DATE
15:11:54
15:11:54 > Task :compileTestJava
15:11:54 Note: Some input files use unchecked or unsafe operations.
15:11:54 Note: Recompile with -Xlint:unchecked for details.
15:11:58
15:11:58 > Task :processTestResources
15:11:58 > Task :testClasses
15:12:01
15:12:01 > Task :test
15:12:01
15:12:01 Gradle Test Executor 1 STANDARD_ERROR
15:12:01     SLF4J: No SLF4J providers were found.
15:12:01     SLF4J: Defaulting to no-operation (NOP) logger implementation
15:12:01     SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
15:12:01     SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
15:12:01     SLF4J: Ignoring binding found at [jar:file:/home/jenkins/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.5/6edffc576ce104ec769d954618764f39f0f0f10d/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
15:12:01     SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
15:13:29
15:13:29 SomeRandomAndroidUiTest STANDARD_ERROR
15:13:29     com.synergy.core.exceptions.SessionNotStartedException: Failed to start session after 3 attempts with results:
[[{"results":"Session 525356b3-bd65-40bf-b9cb-fb855a4e2404 failed to start with error: Failed to decode app package file at
${env.APK_URL}. The AppPackage capability must be either a valid url to an Android APK package OR a valid file path to an
Android APK package!"},{"results":"Session 525356b3-bd65-40bf-b9cb-fb855a4e2404 failed to start with
error: Session 525356b3-bd65-40bf-b9cb-fb855a4e2404 did not have any entries in the device proxy log after app launch.
This is indicative of a network\/proxy issue with your device under test.
To disable this check set the VerifyNetworkConnectivity capability to false."}],[{"results":"Session a511602d-14ca-434f-9d96-93faf9ff5fb5
failed to start with error: Failed to decode app package file at ${env.APK_URL}.
The AppPackage capability must be either a valid url to an Android APK package OR a valid file path
to an Android APK package!"}],[{"results":"Session 5abd7803-4661-4cbb-aed7-d41ef0718f42 failed to start with error:
Failed to decode app package file at ${env.APK_URL}.
The AppPackage capability must be either a valid url to an Android APK package OR a valid file path to an Android APK package!"}]]

92vpleto

92vpleto1#

对于gradle插件,你已经超越了Jenkins模型,它鼓励自包含的可重复构建。一旦你从其他地方(如云)获取东西,它就不是自包含的可重复构建。
有一个环境变量插件,这可能会帮助你,但我建议,不要使用gradle任务,使用shell任务,只是把你的命令,因为你最初,小心退出与失败退出代码,如果任何阶段失败。

APK_URL=$(curl -F file=@"$WORKSPACE/build/SomeProject" -H "Retention: $RETENTION_DAYS" [https://www.myCloudServer.online/fileuploader?key=$MY_KEY](https://www.myCloudServer.online/fileuploader?key=$MY_KEY) |
sed -n 's/.*"file_url":"\([^"]*\)".*/\1/p' | sed 's/\\//g') &&
./gradlew clean test --tests "appium.some.app.Tests.*"  -DincludeTags=$RUN_TYPE -DwebhookUrl=[https://hooks.slack.com/services/someSlackChannel](https://hooks.slack.com/services/someSlackChannel) -DbuildUrl=${APK_URL}

字符串

相关问题