Downgrade Gradle version on Azure Pipeline - linux

After the 7.0 Gradle version my pipeline is crashing.
I want to downgrade it to 6.8.3. I tried with gradle wrapper --gradle-version=6.8.3 but its do nothing.
Btw its a Microsoft-hosted agent with ubuntu-latest VM.

I didn't find other solution, but it's work correctly.
- script: |
wget https://downloads.gradle-dn.com/distributions/gradle-6.8.3-bin.zip
unzip -d . gradle-6.8.3-bin.zip
displayName: Download Gradle 6.8.3
- script: |
./../../gradle-6.8.3/bin/gradle bundleRelease
displayName: Build Bundle

Please add distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip in your gradle/wrapper/gradle-wrapper.properties file.
For example:
Here is the document.
Here is my configuration of pipeline and result:
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Gradle#2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
gradleOptions: '-Xmx3072m'
sonarQubeRunAnalysis: false

Related

uninstall packages in azure function

My azure function app(python) is throwing an exception: module typing has no attribute '_classVar'. A fix for this would be to uninstall the dataclasses package. How do I uninstall this package on a python azure function using pip?
If I run pip uninstall dataclasses, will this reflect on deployment?
If you are using python version 3.7 or greater you need to uninstall the dataclass library using the same pip uninstall dataclasses.
As The dataclasses package is a backport of the Python 3.7 dataclass functionality.
Or, if still you want to exist dataclasses you can downgrade your python version to 3.6.
For more information please refer the below links:
Blog|AttributeError: module ‘typing’ has no attribute ‘_ClassVar’ with Tune
Similar GitHub Issue
I was also having a lot of trouble trying to deploy azure functions from an Azure Devops pipeline with a Python 3.7 environment, so I decided to place this here as it might help someone else with the same problem.
You need to prepare the following yaml file with your respective variables.
trigger:
- {{ branch }}
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: '{{ azureRmConnection.Id }}'
# Function app name
functionAppName: '{{ functionAppName }}'
# Agent VM image name
vmImageName: 'ubuntu-latest'
# Working Directory
workingDirectory: '{{ workingDirectory }}'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion#0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6 # Functions V2 supports Python 3.6 as of today
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionAppLinux
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
These are the key lines after installing the requirements.txt. These will remove the package from the site-packages folder.
rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py
pip uninstall dataclasses will not work because you are not in the right folder.
Hope this helps!

Azure DevOps - Maven Pipeline publish artifacts

I have a scala project, which packages (using maven) perfectly fine locally and also the build pipeline on azure devops works fine. Now I would like to somehow retrieve the produced .jar files in the target folder. Therefore I would like to publish the artifacts. But the .jar files can nowhere be found.
I have the following azure-pipelines.yaml, which copies/publishes the whole folder to the targetFolder, but there is no target folder, only the source code folder is copied. Now my question, how can one publish/access to published artifacts?
trigger:
- azure_devops_pipeline
pool:
vmImage: ubuntu-latest
stages:
- stage: Package
jobs:
- job: Package
steps:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
mavenAuthenticateFeed: true
effectivePomSkip: true
goals: 'package'
options: '-Dmaven.test.skip=true -Pscala-2.12 -Pfat-jar'
#sonarQubeRunAnalysis: false
- stage: PublishArtifacts
jobs:
- job: PublishArtifacts
steps:
- task: CopyFiles#2
inputs:
#SourceFolder: '/home/vsts/work/1/s/target/'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
Eeach job is a seprate machine. SO if you compile and produce files on one job they are not available on next job unless you will publish those files as artifact and download them on another artifact. So if you want to have this working please move them (steps from PublishArtifacts job) to your first job.

How to resolve "unexpected value 'stages' azure pipelines" in Azure devops pipeline yml

I am new to Azure devops. as part of poc, i am trying to build a java based docker image.
so i have following pipeline yaml file
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker#2
displayName: Build an image
inputs:
command: build
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
tags: |
$(tag)
Expected
What i expected, this pipeline need to create a java application (jar file) and then it should create a docker image using this jar
Actual:
i am getting below error
unexpected value 'stages' azure pipelines
I didnt understand the issue...
Appreciated if anybody can help on this..?
Thanks
Please move this into job before your first task - task: Docker#2
steps:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
This is simply syntax issue. If you use steps you cant use stages on the root level. Here you may check syntax.
If you want to have jar creation as separate stage/job you have to define explicitly this as another stage or job. However in that way you need to publish and then download your jar as pipeline artifact.
If you stay with one single job you may just use:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
tag: '$(Build.BuildId)'
steps:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
- task: Docker#2
displayName: Build an image
inputs:
command: build
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
tags: |
$(tag)

Does Azure DevOps Pipelines cache some data accross runs

I'm new to Azure DevOps and pipelines, and I ran into an issue running the same pipeline multiple times in a short period.
In brief, I created a pipeline to simply build a .Net project with MSBuild and generate an artifact. The pipeline trigger on change in master branch.
The first time, it worked, I can download the artifact and execute the program without any issue. Now if I do a change in the master branch 5 minutes later adding an option to my program, the pipeline runs successfully, however when running program stored in the generated artifact, my new option is not there.
I'm probably doing something stupid there, but I don't understand why I have this behaviour.
Is there any kind of caching and how can I have fresh build everytime ?
== EDIT ==
Here is my YAML definition as requested
Basically, steps are:
Checkout solution with all submodule
Nuget restore packages for all required projects
MSBuild task
Archive the output
Publish artifact.
trigger:
- master
pool:
demands: azureps
vmImage: 'windows-latest'
steps:
- checkout: "git://GSS-CMDB-Tools/GSSAM_Code"
submodules: true
persistCredentials: true
- task: NuGetCommand#2
inputs:
command: 'custom'
arguments: 'restore ADDMSync/packages.config -SolutionDirectory .'
- task: NuGetCommand#2
inputs:
command: 'custom'
arguments: 'restore GSSAM/packages.config -SolutionDirectory .'
- task: NuGetCommand#2
inputs:
command: 'custom'
arguments: 'restore GSSAM.ADDMRest/packages.config -SolutionDirectory .'
- task: NuGetCommand#2
inputs:
command: 'custom'
arguments: 'restore GSSAM.SNOWRest/packages.config -SolutionDirectory .'
- task: MSBuild#1
inputs:
solution: 'ADDMSync/ADDMSync.csproj'
msbuildArchitecture: 'x64'
configuration: 'Release'
msbuildArguments: '/p:PostBuildEvent='
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
mv ADDMSync/bin/Release ADDMSync/Bin/ADDMSync
rm ADDMSync/bin/ADDMSync/*.pdb
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: 'ADDMSync/bin/ADDMSync'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/ADDMSync.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/ADDMSync.zip'
ArtifactName: 'ADDMSync'
publishLocation: 'Container'
Thanks a lot
Rémi
OK I think I understand what happens.
What I did was to commit and push all submodules required by the build. However I did not commit the modification of the solution itself. By doing so it makes it working.
I don't understand why for now, I guess it's link to the way the checkout task works.

Azure DevOps build fails after upgrading app to from ASP.NET Core 2.2 to ASP.NET Core 3.1

I have a build which works fine locally (VSCode, .NET Core 3.1.101) but fails with the following message when run in an Azure DevOps Pipeline.
My pipeline is stripped down to the most basic:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
And that results in this error message:
Version 3.1.101 of the .NET Core SDK requires at least version 16.3.0 of MSBuild. The current available version of MSBuild is 15.9.21.664. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
I can't find a way to change the version of MSBuild that the pipeline runs and changing to an older version of .NET Core surely defeats the purpose of upgrading?
Is there any way to build a.NET Core 3.1 solution on Azure DevOps?
I do not see anywhere you are having the dotnet build task, you need to have the dotnetbuild task with the version configured,
steps:
- task: UseDotNet#2
displayName: ".NET Core 3.1.x"
inputs:
version: '3.1.x'
packageType: sdk
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
Refer this article.
You should be able to restore nuget packages, compile nad run unit tests using this YAML
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
rootDirectory: '$(Build.SourcesDirectory)'
steps:
- task: DotNetCoreCLI#2
displayName: Restore nuget packages
inputs:
command: restore
projects: '**/*.csproj'
workingDirectory: $(rootDirectory)
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '$(rootDirectory)/*.sln'
arguments: '--configuration $(buildConfiguration)'
# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
workingDirectory: $(rootDirectory)
I assumed that you solution file is in the root directory. If you use global json please set sdk version to 3.1.201 otherwise another steo may be required.
global.json
{
"sdk": {
"version": "3.1.201",
"rollForward": "latestFeature"
}
}

Resources