Azure Pipeline配置JDK17后JVM仍为11,如何调整?
问题
我已在azure-pipeline.yml中将jdkVersion设置为17,但执行Pipeline时,日志显示JVM版本为11.0.22(Eclipse Adoptium 11.0.22+7)。以下是Pipeline日志及配置内容,请问需排查哪些位置来正确设置JVM版本?
Pipeline日志
Gradle 8.5 Build time: 2023-11-29 14:08:57 UTC Revision: 28aca86a7180baa17117e0e5ba01d8ea9feca598 Kotlin: 1.9.20 Groovy: 3.0.17 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 11.0.22 (Eclipse Adoptium 11.0.22+7) OS: Linux 6.2.0-1019-azure amd64
azure-pipeline.yml配置
variables: - name: projectName value: 'reports' - name: jdkVersion value: '17' - name: GIT_COMMIT_ID value: $(Build.SourceVersion) - name: SNYK_API value: https://app.eu.snyk.io/api/ trigger: branches: include: - master resources: repositories: - repository: azure-pipelines-templates type: git name: "name/azure-pipelines-templates" ref: refs/tags/v10 pool: vmImage: 'ubuntu-latest' steps: - script: echo "##vso[task.setvariable variable=ComponentVersion]$(./gradlew -q :printVersion)" displayName: Get Component Version - template: gradle/gradle_ci.yaml@azure-pipelines-templates parameters: jdkVersion: $(jdkVersion) sonarServiceConnection: 'sonarCloud.service.connection' sonarProjectKey: 'OpenWebTechnologyFoundry_expense-reports' sonarProjectName: 'expense-reports' containerRegistry: 'docker.registry' containerRegistryUrl: 'registrysharedinternalapps.azurecr.io' dockerRepository: $(projectName) dockerTag: $(ComponentVersion)-${{ variables.GIT_COMMIT_ID }} skipTests: false codeCoverageToolOption: none useGradleToBuildDockerImage: false dockerBuildAndPush: true testTasks: build snykSkip: false snykServiceConnectionName: 'snyk_eu_service_connection' snykOrgUrlName: 'openwt-internal-projects' snykTasks: - snykFailOnIssues: false snykAdditionalArguments: '-d --all-projects -exclude=build.gradle' - snykFailOnIssues: false snykTargetFile: 'build.gradle' snykProjectName: 'expense-report' snykAdditionalArguments: '-d'
需排查的位置
- 检查模板
gradle_ci.yaml的JDK配置逻辑:你传递了jdkVersion参数给模板,但模板里必须有实际生效的JDK切换逻辑,比如是否使用了Azure Pipeline的UseJavaVersion任务,或者是否通过环境变量、Gradle参数指定了JDK路径。如果模板里没用到这个参数,传了也不会生效。 - 验证参数传递是否正确:原配置中
parameters下的参数缩进存在混乱,可能导致jdkVersion参数没正确传递到模板中。要确保所有参数都在parameters的缩进层级下。 - 排查前置步骤的JDK影响:第一个步骤执行了
./gradlew -q :printVersion,这一步会直接使用环境中的JDK(或Gradle Wrapper指定的JDK)。如果这一步已经用了JDK11,后续步骤可能继承这个环境,需要确认这一步是否需要先切换到JDK17再执行。 - 检查Gradle Wrapper的配置:项目中
gradle/wrapper/gradle-wrapper.properties的distributionUrl可能指定了带JDK11的Gradle发行版,或者build.gradle里通过java.toolchain指定了JDK11版本,这会覆盖Pipeline的JDK设置。 - 确认虚拟机镜像的默认JDK:
ubuntu-latest镜像默认可能预装了JDK11,如果模板里没有显式切换到JDK17,就会使用默认版本。需要确认模板中是否有安装/切换到JDK17的步骤。
内容的提问来源于stack exchange,提问作者StefanoSKAL
相关产品推荐
相关产品推荐

