[英]Azure DevOps Pipeline for Java Project with self hosted agent
We are having a set of Java Projects which were developed using different JDK versions, different versions of Gradle and Maven were used in projects.我们有一组使用不同 JDK 版本开发的 Java 项目,项目中使用了不同版本的 Gradle 和 Maven。
We are supposed to create a Azure DevOps Pipeline using Self Hosted Agent
and as of now build agent server was installed with JDK 11.我们应该使用
Self Hosted Agent
创建 Azure DevOps 管道,并且到目前为止,构建代理服务器已安装 JDK 11。
How to create pipeline to handle such variety of projects?如何创建管道来处理如此多样化的项目? Do we need to install multiple JDK versions in Self Hosted Agent or any other better way?
我们是否需要在 Self Hosted Agent 或其他更好的方式中安装多个 JDK 版本?
Yes, you need to install multiple JDK versions if you want to use Self Hosted Agent.是的,如果您想使用 Self Hosted Agent,您需要安装多个 JDK 版本。 The better way is to use Microsoft-hoseted agent because it has some versions of JDK pre-installed.
更好的方法是使用 Microsoft 托管代理,因为它预装了一些版本的 JDK。 You can refer to the document about Build environment and Build using multiple versions .
可以参考Build environment和Build using multiple versions的文档。
Update:更新:
Here are my samples of Gradle with self-hosted agent:这是我的带有自托管代理的 Gradle 示例:
1.Use java tool install task: 1.使用java工具安装任务:
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'LocalDirectory'
jdkFile: 'C:\jdk-11.0.10.zip'
cleanDestinationDirectory: false
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false
- task: JavaToolInstaller@0
inputs:
versionSpec: '8'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'LocalDirectory'
jdkFile: 'C:\jdk1.8.0_281.zip'
cleanDestinationDirectory: false
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false
JDK file of java tool install task: java工具安装任务的JDK文件:
Applicable when jdkSourceOption == LocalDirectory.当 jdkSourceOption == LocalDirectory 时适用。 Specify the path to the jdk archive file that contains the compressed JDK.
指定包含压缩 JDK 的 jdk 归档文件的路径。 The path could be in your source repository or a local path on the agent.
该路径可以在您的源存储库中或代理上的本地路径中。 The file should be an archive (.zip, .tar.gz, .7z), containing bin folder either on the root level or inside a single directory.
该文件应该是一个存档(.zip、.tar.gz、.7z),包含根级别或单个目录中的 bin 文件夹。
2.Use gradle task directly: 2.直接使用gradle任务:
steps:
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'Path'
jdkDirectory: 'C:\Program Files\Java\jdk-11.0.10'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'Path'
jdkDirectory: 'C:\Program Files\Java\jdk1.8.0_281'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false
The other answer requires the JDK binary to be present at a location.另一个答案要求 JDK 二进制文件存在于某个位置。 In its absence:
在它缺席的情况下:
- task: BASH@3
displayName: 'install-java8'
inputs:
targetType: 'inline'
script: |
rm -rf /opt/jdk
mkdir /opt/jdk
wget https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u322-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u322b06.tar.gz
tar -zxf OpenJDK8U-jdk_x64_linux_hotspot_8u322b06.tar.gz -C /opt/jdk
export PATH=$PWD/jdk8u322-b06/bin:$PATH
update-alternatives --install /usr/bin/java java /opt/jdk/jdk8u322-b06/bin/java 100 && \
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk8u322-b06/bin/javac 100 && \
update-alternatives --install /usr/bin/jar jar /opt/jdk/jdk8u322-b06/bin/jar 100 && \
echo 'export JAVA_HOME=/opt/jdk/jdk8u322-b06/' >> /etc/profile.d/java.sh
java -version
- task: BASH@3
displayName: 'verify java8 installation'
inputs:
targetType: 'inline'
script: |
source /etc/profile.d/java.sh
java -version
echo $JAVA_HOME
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.