【问题标题】:Passing properties to ANT build.xml file将属性传递给 ANT build.xml 文件
【发布时间】:2020-09-08 22:23:30
【问题描述】:

我是 Stack Overflow 和 Azure 的新手。

我想要一个项目中的多个存储库。许多存储库将具有经常更改的源代码(repoX),一个具有很少更改的大型 jar 文件(repo2)。 Repo2 将用于不同 repoX 中的 ANT 构建。在 Azure Pipeline for repoX 中,我想将 repo2 的路径传递给 build.xml 的类路径,但似乎找不到正确的语法。我熟悉 ANT,只需要语法。 Azure 帮助显示了几种设置构建属性的方法,例如变量、环境等。

感谢您的帮助。

【问题讨论】:

    标签: azure azure-devops


    【解决方案1】:

    非常感谢您的帮助。我能够将参数传递给我的构建文件。我无法让替换令牌任务工作(我认为它已被弃用),但由于 ANT 属性是不可变的,所以当我在 ANT 任务 OPTIONS 中设置我的类路径变量时,它会在构建文件中被拾取。这是我的管道:

    trigger:
    - master
    
    pool:
      vmImage: 'ubuntu-latest'
    
    resources:
      repositories:
      - repository: THE_JDK
        type: git
        name: FOLDER/THE_JDK
    
    steps:
    - checkout: self
    - checkout: THE_JDK
    - script: |
        echo $(Build.SourcesDirectory)
        ls $(Build.SourcesDirectory) *
        
    - powershell: Write-Host "##vso[task.setvariable variable=jdk.home;]$(Build.SourcesDirectory)/THE_JDK"    
    
    - task: Ant@1
      inputs:
        buildFile: 'trunk/TheApp/build/build.xml'
        options: -Djdk.home=$(jdk.home)
        targets: 'dist-trunk'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.8'
        jdkArchitectureOption: 'x64'
        publishJUnitResults: true
        testResultsFiles: '**/TEST-*.xml'
    

    【讨论】:

    • 很高兴看到您的问题已得到解决。您可以Accept it as an Answer 一次,这对阅读此主题的其他社区成员会有所帮助。
    【解决方案2】:

    你可以尝试使用multi repo checkout

    resources:
      repositories:
        - repository: devops
          type: github
          name: kmadof/devops-templates
          endpoint: kmadof
    
    steps:
    - checkout: self
    - checkout: devops
    - script: |
        echo $(Build.SourcesDirectory)
        ls $(Build.SourcesDirectory) *
    

    我们在这里签出两个 repo,一个将转到 devops-manual 文件夹(自我 repo,在您的情况下应该是 repoX),另一个将转到 devops-templates 文件夹(在您的情况下是 repo2)。

    现在您应该在变量中分配 repo2 的路径。为此,您应该使用日志记录命令:

    - powershell: Write-Host "##vso[task.setvariable variable=repoxpath;]$(Build.SourcesDirectory)/devops-templates"
    

    现在我们应该用路径更新build.xml,因此我建议使用Replace Token task

    - task: replacetokens@3
      inputs:
        targetFiles: '<path-t-your-build.xml-file>'
        encoding: 'auto'
        writeBOM: true
        actionOnMissing: 'warn'
        keepToken: false
        tokenPrefix: '#{'
        tokenSuffix: '}#'
        useLegacyPattern: false
        enableTelemetry: true
    

    在你想放置路径的地方你应该有这个令牌#{repoxpath}#

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      相关资源
      最近更新 更多