diff --git a/package-pipeline.ps1 b/package-pipeline.ps1 index 0dac26ae..3460de42 100644 --- a/package-pipeline.ps1 +++ b/package-pipeline.ps1 @@ -5,20 +5,16 @@ param ( # A function that checks exit codes and fails script if an error is found function StopOnFailedExecution { if ($LastExitCode) - { + { exit $LastExitCode } } -$ApplicationInsightsAgentVersion = '3.5.4' -$ApplicationInsightsAgentFilename = "applicationinsights-agent-${ApplicationInsightsAgentVersion}.jar" -$ApplicationInsightsAgentUrl = "https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion}/${ApplicationInsightsAgentFilename}" - -Write-Host "Building azure-functions-java-worker" -mvn clean package --no-transfer-progress -B +Write-Host "Building azure-functions-java-worker with appinsights profile" +mvn clean package --no-transfer-progress -B -P appinsights StopOnFailedExecution -Write-Host "Creating nuget package Microsoft.Azure.Functions.JavaWorker" +Write-Host "Creating nuget package Microsoft.Azure.Functions.JavaWorker" Write-Host "buildNumber: " $buildNumber Get-Command nuget StopOnFailedExecution @@ -30,12 +26,13 @@ copy-item ./worker.config.json pkg copy-item ./tools/AzureFunctionsJavaWorker.nuspec pkg/ copy-item ./annotationLib pkg/annotationLib -Recurse -# Download application insights agent from maven central -$ApplicationInsightsAgentFile = [System.IO.Path]::Combine($PSScriptRoot, $ApplicationInsightsAgentFilename) +# locate the agent jar produced by the `appinsights` Maven profile +$ApplicationInsightsAgentFile = [System.IO.Path]::Combine($PSScriptRoot, 'target', 'agent', 'applicationinsights-agent.jar') -# local testing cleanup -if (Test-Path -Path $ApplicationInsightsAgentFile) { - Remove-Item -Path $ApplicationInsightsAgentFile +if (!(Test-Path -Path $ApplicationInsightsAgentFile)) { + Write-Host "Error: $ApplicationInsightsAgentFile not found." + Write-Host "Make sure you enabled the 'appinsights' Maven profile that copies the AI agent to target/agent/." + exit 1 } # local testing cleanup @@ -56,20 +53,6 @@ if (-not(Test-Path -Path $extract)) { exit 1 } -echo "Start downloading '$ApplicationInsightsAgentUrl' to '$PSScriptRoot'" -try { - Invoke-WebRequest -Uri $ApplicationInsightsAgentUrl -OutFile $ApplicationInsightsAgentFile -} catch { - echo "An error occurred. Download fails" $ApplicationInsightsAgentFile - echo "Exiting" - exit 1 -} - -if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) { - echo "$ApplicationInsightsAgentFile do not exist." - exit 1 -} - echo "Start extracting content from $ApplicationInsightsAgentFilename to extract folder" cd -Path $extract -PassThru jar xf $ApplicationInsightsAgentFile @@ -82,14 +65,6 @@ $manifest = "$extract\META-INF\MANIFEST.MF" $newContent = (Get-Content -Raw $manifest | Select-String -Pattern '(?sm)^(.*?\r?\n)\r?\n').Matches[0].Groups[1].Value Set-Content -Path $manifest $newContent -Remove-Item $ApplicationInsightsAgentFile -if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) { - echo "Delete the original $ApplicationInsightsAgentFilename successfully" -} else { - echo "Fail to delete original source $ApplicationInsightsAgentFilename" - exit 1 -} - $agent = new-item -type directory -force $PSScriptRoot\agent $filename = "applicationinsights-agent.jar" $result = [System.IO.Path]::Combine($agent, $filename) diff --git a/pom.xml b/pom.xml index 4d58bfbd..caacaf72 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 2.2.0 5.9.1 4.11.0 + 3.6.2 @@ -321,4 +322,51 @@ + + + appinsights + + + com.microsoft.azure + applicationinsights-agent + ${appinsights.agents.version} + provided + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.5.0 + + + copy-ai-agent + package + + copy + + + + + com.microsoft.azure + applicationinsights-agent + ${appinsights.agents.version} + ${project.build.directory}/agent + applicationinsights-agent.jar + + + + + + + + + + \ No newline at end of file diff --git a/setup-tests-pipeline.ps1 b/setup-tests-pipeline.ps1 index d545a82b..d146a491 100644 --- a/setup-tests-pipeline.ps1 +++ b/setup-tests-pipeline.ps1 @@ -29,10 +29,6 @@ else $FUNC_CLI_DIRECTORY = Join-Path $PSScriptRoot 'Azure.Functions.Cli' -$ApplicationInsightsAgentVersion = '3.5.4' -$ApplicationInsightsAgentFilename = "applicationinsights-agent-${ApplicationInsightsAgentVersion}.jar" -$ApplicationInsightsAgentUrl = "https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion}/${ApplicationInsightsAgentFilename}" - Write-Host 'Deleting the Core Tools if exists...' Remove-Item -Force "$FUNC_CLI_DIRECTORY.zip" -ErrorAction Ignore Remove-Item -Recurse -Force $FUNC_CLI_DIRECTORY -ErrorAction Ignore @@ -58,83 +54,6 @@ if (-not $UseCoreToolsBuildFromIntegrationTests.IsPresent) Copy-Item "$PSScriptRoot/worker.config.json" "$FUNC_CLI_DIRECTORY/workers/java" -Force -Verbose Write-Host "Copying worker.config.json and annotationLib to worker directory" Copy-Item "$PSScriptRoot/annotationLib" "$FUNC_CLI_DIRECTORY/workers/java" -Recurse -Verbose -Force - - # Download application insights agent from maven central - $ApplicationInsightsAgentFile = [System.IO.Path]::Combine($PSScriptRoot, $ApplicationInsightsAgentFilename) - - # local testing cleanup - if (Test-Path -Path $ApplicationInsightsAgentFile) { - Remove-Item -Path $ApplicationInsightsAgentFile - } - - # local testing cleanup - $oldOutput = [System.IO.Path]::Combine($PSScriptRoot, "agent") - if (Test-Path -Path $oldOutput) { - Remove-Item -Path $oldOutput -Recurse - } - - # local testing cleanup - $oldExtract = [System.IO.Path]::Combine($PSScriptRoot, "extract") - if (Test-Path -Path $oldExtract) { - Remove-Item -Path $oldExtract -Recurse - } - - echo "Start downloading '$ApplicationInsightsAgentUrl' to '$PSScriptRoot'" - try { - Invoke-WebRequest -Uri $ApplicationInsightsAgentUrl -OutFile $ApplicationInsightsAgentFile - } catch { - echo "An error occurred. Download fails" $ApplicationInsightsAgentFile - echo "Exiting" - exit 1 - } - - if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) { - echo "$ApplicationInsightsAgentFile do not exist." - exit 1 - } - - $extract = new-item -type directory -force $PSScriptRoot\extract - if (-not(Test-Path -Path $extract)) { - echo "Fail to create a new directory $extract" - exit 1 - } - - echo "Start extracting content from $ApplicationInsightsAgentFilename to extract folder" - cd -Path $extract -PassThru - jar xf $ApplicationInsightsAgentFile - cd $PSScriptRoot - echo "Done extracting" - - echo "Unsign $ApplicationInsightsAgentFilename" - Remove-Item $extract\META-INF\MSFTSIG.* - $manifest = "$extract\META-INF\MANIFEST.MF" - $newContent = (Get-Content -Raw $manifest | Select-String -Pattern '(?sm)^(.*?\r?\n)\r?\n').Matches[0].Groups[1].Value - Set-Content -Path $manifest $newContent - - Remove-Item $ApplicationInsightsAgentFile - if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) { - echo "Delete the original $ApplicationInsightsAgentFilename successfully" - } else { - echo "Fail to delete original source $ApplicationInsightsAgentFilename" - exit 1 - } - - $agent = new-item -type directory -force $PSScriptRoot\agent - $filename = "applicationinsights-agent.jar" - $result = [System.IO.Path]::Combine($agent, $filename) - echo "re-jar $filename" - - cd -Path $extract -PassThru - jar cfm $result META-INF/MANIFEST.MF . - - if (-not(Test-Path -Path $result)) { - echo "Fail to re-archive $filename" - exit 1 - } - - Write-Host "Creating the functions.codeless file" - New-Item -path $PSScriptRoot\agent -type file -name "functions.codeless" - Write-Host "Copying the unsigned Application Insights Agent to worker directory" Copy-Item "$PSScriptRoot/agent" "$FUNC_CLI_DIRECTORY/workers/java" -Recurse -Verbose -Force }