admin管理员组

文章数量:1122846

I have azure pipeline created from yml file code-analysis-pipeline.yml in repository which is on the same level as gradle.properties. On gradle.properties there is a variable VERSION_CODE and on code-anlysis-pipeline.yml, I need to access the VERSION_CODE variable. Is there anyway to access this variable from the yml file?

- task: PowerShell@2
  displayName: Run gradle sonar
  inputs:
    targetType: 'inline'
    pwsh: true
    workingDirectory: ${{ parameters.workingDirectory }}
    script: |
        $GRADLE_COMMAND = "./gradlew sonar"
        $GRADLE_COMMAND += " ""-Dsonar.projectVersion=$(VERSION_CODE_FROM_GRADLE_PROPERTIES)"""

I have azure pipeline created from yml file code-analysis-pipeline.yml in repository which is on the same level as gradle.properties. On gradle.properties there is a variable VERSION_CODE and on code-anlysis-pipeline.yml, I need to access the VERSION_CODE variable. Is there anyway to access this variable from the yml file?

- task: PowerShell@2
  displayName: Run gradle sonar
  inputs:
    targetType: 'inline'
    pwsh: true
    workingDirectory: ${{ parameters.workingDirectory }}
    script: |
        $GRADLE_COMMAND = "./gradlew sonar"
        $GRADLE_COMMAND += " ""-Dsonar.projectVersion=$(VERSION_CODE_FROM_GRADLE_PROPERTIES)"""
Share Improve this question asked yesterday Kevin LeeKevin Lee 3554 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

you are using an powershell task, might just read the file and then filter the line by key name?

- task: PowerShell@2
    displayName: Run gradle sonar
    inputs:
        targetType: 'inline'
        pwsh: true
        workingDirectory: ${{ parameters.workingDirectory }}
        script: |
            $searchText = "VERSION_CODE"
            $filteredLine = Get-Content -Path 'gradle.properties' | Select-String -Pattern $searchText
                
            if ($filteredLine) {
                $splitLine = $filteredLine -split '='
                $version = $splitLine[1].Trim()
                $version
            }
            $GRADLE_COMMAND = "./gradlew sonar"
            $GRADLE_COMMAND += " ""-Dsonar.projectVersion=$(version)"""

本文标签: androidGetting variable from gradleproperties to Azure DevOps pipeline ymlStack Overflow