ci(jenkins): adapt Jenkinsfile for Windows Jenkins node
这个提交包含在:
父节点
499f557bf7
当前提交
3937c29552
129
Jenkinsfile
vendored
129
Jenkinsfile
vendored
@ -1,89 +1,91 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
parameters {
|
||||||
ANDROID_HOME = '/Users/xuqinmin/Library/Android/sdk'
|
string(name: 'BRANCH', defaultValue: 'main', description: 'Git 分支名')
|
||||||
NEXUS_USER = credentials('nexus-android-user')
|
string(name: 'VERSION', defaultValue: '', description: '发布版本号(留空使用 gradle.properties 中的 PUBLISH_VERSION)')
|
||||||
NEXUS_PASS = credentials('nexus-android-pass')
|
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '是否运行自动化测试')
|
||||||
AVD_1 = 'Pixel_9_Pro'
|
booleanParam(name: 'PUBLISH', defaultValue: true, description: '是否发布到 Nexus')
|
||||||
AVD_2 = 'Pixel_9_Pro_2'
|
|
||||||
EMULATOR_BIN = "${ANDROID_HOME}/emulator/emulator"
|
|
||||||
ADB = "${ANDROID_HOME}/platform-tools/adb"
|
|
||||||
TEST_PKG = 'com.xuqm.demo.test'
|
|
||||||
RUNNER = 'androidx.test.runner.AndroidJUnitRunner'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
environment {
|
||||||
timeout(time: 60, unit: 'MINUTES')
|
NEXUS_USER = credentials('nexus-android-user')
|
||||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
NEXUS_PASS = credentials('nexus-android-pass')
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Build') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew :sample-app:assembleDebug :sample-app:assembleDebugAndroidTest --no-daemon'
|
checkout scm
|
||||||
|
script {
|
||||||
|
if (params.VERSION?.trim()) {
|
||||||
|
bat "powershell -Command \"(Get-Content gradle.properties) -replace '^PUBLISH_VERSION=.*', 'PUBLISH_VERSION=${params.VERSION}' | Set-Content gradle.properties\""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build AARs & APKs') {
|
||||||
|
steps {
|
||||||
|
bat 'gradlew.bat :sample-app:assembleDebug :sample-app:assembleDebugAndroidTest --no-daemon'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Start Emulators') {
|
stage('Start Emulators') {
|
||||||
|
when { expression { return params.RUN_TESTS } }
|
||||||
steps {
|
steps {
|
||||||
sh """
|
bat '''
|
||||||
${EMULATOR_BIN} -avd ${AVD_1} -no-audio -no-boot-anim -no-snapshot-save -no-window &
|
start /B emulator -avd Pixel_9_Pro -no-audio -no-boot-anim -no-snapshot-save -no-window
|
||||||
${EMULATOR_BIN} -avd ${AVD_2} -no-audio -no-boot-anim -no-snapshot-save -no-window &
|
start /B emulator -avd Pixel_9_Pro_2 -no-audio -no-boot-anim -no-snapshot-save -no-window
|
||||||
${ADB} wait-for-device
|
adb wait-for-device
|
||||||
sleep 20
|
timeout /t 20 /nobreak >nul
|
||||||
${ADB} devices
|
adb devices
|
||||||
"""
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Install APKs') {
|
stage('Install APKs') {
|
||||||
|
when { expression { return params.RUN_TESTS } }
|
||||||
steps {
|
steps {
|
||||||
sh """
|
bat '''
|
||||||
APK=sample-app/build/outputs/apk/debug/sample-app-debug.apk
|
set APK=sample-app\\build\\outputs\\apk\\debug\\sample-app-debug.apk
|
||||||
TEST_APK=sample-app/build/outputs/apk/androidTest/debug/sample-app-debug-androidTest.apk
|
set TEST_APK=sample-app\\build\\outputs\\apk\\androidTest\\debug\\sample-app-debug-androidTest.apk
|
||||||
for DEV in emulator-5554 emulator-5556; do
|
for %%D in (emulator-5554 emulator-5556) do (
|
||||||
${ADB} -s \$DEV install -r "\$APK"
|
adb -s %%D install -r "%APK%"
|
||||||
${ADB} -s \$DEV install -r "\$TEST_APK"
|
adb -s %%D install -r "%TEST_APK%"
|
||||||
done
|
)
|
||||||
"""
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Single-Device Tests') {
|
stage('Single-Device Tests') {
|
||||||
|
when { expression { return params.RUN_TESTS } }
|
||||||
steps {
|
steps {
|
||||||
sh """
|
bat '''
|
||||||
ALL_SINGLE="com.xuqm.sdk.sample.SdkIntegrationTest,\
|
set ALL_SINGLE=com.xuqm.sdk.sample.SdkIntegrationTest,com.xuqm.sdk.sample.PushSdkTest,com.xuqm.sdk.sample.NetworkResilienceTest
|
||||||
com.xuqm.sdk.sample.PushSdkTest,\
|
adb -s emulator-5554 shell am instrument -w -r -e class "%ALL_SINGLE%" "com.xuqm.demo.test/androidx.test.runner.AndroidJUnitRunner" > test-results-5554.txt
|
||||||
com.xuqm.sdk.sample.NetworkResilienceTest"
|
findstr /C:"FAILURES" test-results-5554.txt && exit 1 || exit 0
|
||||||
${ADB} -s emulator-5554 shell am instrument -w -r \\
|
'''
|
||||||
-e class "\${ALL_SINGLE}" \\
|
|
||||||
"${TEST_PKG}/${RUNNER}" | tee test-results-5554.txt
|
|
||||||
grep -q "FAILURES" test-results-5554.txt && exit 1 || true
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Cross-Device Tests') {
|
stage('Cross-Device Tests') {
|
||||||
|
when { expression { return params.RUN_TESTS } }
|
||||||
parallel {
|
parallel {
|
||||||
stage('Sender (5554)') {
|
stage('Sender (5554)') {
|
||||||
steps {
|
steps {
|
||||||
sh """
|
bat '''
|
||||||
${ADB} -s emulator-5554 shell am instrument -w -r \\
|
adb -s emulator-5554 shell am instrument -w -r -e class "com.xuqm.sdk.sample.CrossDeviceSenderTest" "com.xuqm.demo.test/androidx.test.runner.AndroidJUnitRunner" > cross-sender.txt
|
||||||
-e class "com.xuqm.sdk.sample.CrossDeviceSenderTest" \\
|
findstr /C:"FAILURES" cross-sender.txt && exit 1 || exit 0
|
||||||
"${TEST_PKG}/${RUNNER}" | tee cross-sender.txt
|
'''
|
||||||
grep -q "FAILURES" cross-sender.txt && exit 1 || true
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Receiver (5556)') {
|
stage('Receiver (5556)') {
|
||||||
steps {
|
steps {
|
||||||
sh """
|
bat '''
|
||||||
${ADB} -s emulator-5556 shell am instrument -w -r \\
|
adb -s emulator-5556 shell am instrument -w -r -e class "com.xuqm.sdk.sample.CrossDeviceReceiverTest" "com.xuqm.demo.test/androidx.test.runner.AndroidJUnitRunner" > cross-receiver.txt
|
||||||
-e class "com.xuqm.sdk.sample.CrossDeviceReceiverTest" \\
|
findstr /C:"FAILURES" cross-receiver.txt && exit 1 || exit 0
|
||||||
"${TEST_PKG}/${RUNNER}" | tee cross-receiver.txt
|
'''
|
||||||
grep -q "FAILURES" cross-receiver.txt && exit 1 || true
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,29 +93,32 @@ com.xuqm.sdk.sample.NetworkResilienceTest"
|
|||||||
|
|
||||||
stage('Publish to Nexus') {
|
stage('Publish to Nexus') {
|
||||||
when {
|
when {
|
||||||
branch 'main'
|
allOf {
|
||||||
|
branch 'main'
|
||||||
|
expression { return params.PUBLISH }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh """
|
script {
|
||||||
./gradlew publish --no-daemon \\
|
def versionArg = params.VERSION?.trim() ? "-PPUBLISH_VERSION=${params.VERSION}" : ''
|
||||||
-PNEXUS_USER=\${NEXUS_USER} \\
|
bat "gradlew.bat publish ${versionArg} -PNEXUS_USER=%NEXUS_USER% -PNEXUS_PASSWORD=%NEXUS_PASS% --no-daemon"
|
||||||
-PNEXUS_PASSWORD=\${NEXUS_PASS}
|
}
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
sh "${ADB} emu kill || true"
|
bat 'adb emu kill || exit 0'
|
||||||
archiveArtifacts artifacts: 'test-results-*.txt, cross-*.txt', allowEmptyArchive: true
|
archiveArtifacts artifacts: 'test-results-*.txt, cross-*.txt', allowEmptyArchive: true
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
sh """
|
bat '''
|
||||||
${ADB} -s emulator-5554 logcat -d -s XuqmImSDK:D XuqmPushSDK:W XuqmUpdateSDK:D > logcat-5554.txt || true
|
adb -s emulator-5554 logcat -d -s XuqmImSDK:D XuqmPushSDK:W XuqmUpdateSDK:D > logcat-5554.txt || exit 0
|
||||||
${ADB} -s emulator-5556 logcat -d -s XuqmImSDK:D XuqmPushSDK:W XuqmUpdateSDK:D > logcat-5556.txt || true
|
adb -s emulator-5556 logcat -d -s XuqmImSDK:D XuqmPushSDK:W XuqmUpdateSDK:D > logcat-5556.txt || exit 0
|
||||||
"""
|
'''
|
||||||
archiveArtifacts artifacts: 'logcat-*.txt', allowEmptyArchive: true
|
archiveArtifacts artifacts: 'logcat-*.txt', allowEmptyArchive: true
|
||||||
}
|
}
|
||||||
|
success { echo "✅ Android SDK 构建成功" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户