简体   繁体   English

Azure 用于 Java 项目的 DevOps 管道,带有自托管代理

[英]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 environmentBuild 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.

相关问题 如何在 Azure 管道 Microsoft 托管代理上升级 java 版本? - How to upgrade java version on an Azure pipeline Microsoft-hosted agent? 在 Bitbucket 上托管的 Maven 项目上,我在哪里设置 Azure DevOps 管道的 Nexus 凭据? - Where do I set the Nexus credentials for an Azure DevOps pipeline on a Maven project hosted on Bitbucket? Azure Devops 管道:访问 xml 文件中的代理 JAVA_HOME 变量 - Azure Devops Pipeline : Accessing agent JAVA_HOME variable in xml file Azure 管道无法识别自托管代理中的 mvn - Azure Pipelines does not recognize mvn in self hosted agent 如何在 Azure DevOps 管道中安装 Java? - How to install Java in an Azure DevOps pipeline? 适用于不同环境的 Azure JAVA 函数 + DevOps 管道 - Azure JAVA Functions + DevOps pipeline for different environment 未处理:未找到 mavenPOMFile - Azure DevOps 管道 Java Function App - Unhandled: Not found mavenPOMFile - Azure DevOps pipeline for Java Function App 在 Azure DevOps 发布管道中运行 Java Selenium 测试 - Run Java Selenium tests in Azure DevOps release pipeline Azure Dev Ops 管道 java 项目 - Azure Dev Ops pipeline java project 如何在不下载的情况下在 Azure Devops Agent 中使用特定版本的 Java? - How to you use a specific version of Java in Azure Devops Agent without downloading?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM