I want to understand if it is possible to install/import a custom module and have its functions available for multiple Azure Powershell Tasks within the same Azure DevOps release pipeline stage.
Background
I have a custom powershell module (written by myself) that is packaged correctly into a nuget package by an Azure DevOps Build pipeline. This is stored in Azure Artifacts.
I reference this Azure Artifacts Powershell module in the Release pipeline and when run, the pipeline extracts correctly and I can see all the expected powershell scripts within the $Agent.ReleaseDirectory
In the DevOps Release pipeline Stage I have two tasks
- Task 1) An initialisation Azure Powershell task intended to load the module and make the module functions available to the session and therefore available to later Azure Powershell tasks.
- Task 2) A 'test' Azure Powershell task that calls a "Get-BuildNumber" powershell function that is part of the module.
The Problem
- If I call "Get-BuildNumber" from Task 1 (that loads the module) then I get back my build number correctly. A write-host command confirms the value is correct.
- If I call "Get-BuildNumber" from Task 2 (the one that tests the functions are available) then I get the response
The term 'Get-BuildNumber' is not recognized as the name of a cmdlet, function, script file, or operable program.
Analysis
- It appears that the imported module is scoped to a single azure powershell task but I'd rather not have to load the module for each task.
- I'm using the following commands in task 1 and the module itself 'dot sources' the script functions, making each function available in the session scope. On my local machine this all works correctly.
$currentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module (Join-Path $currentDir "modules\deploy") -Force
$env:PSUTILSPATH = (Join-Path $currentDir "modules")
The deploy.psm1 module file just contains the following
$functions = Get-ChildItem -Recurse $PSScriptRoot -Include *.ps1 | ? { $_ -notmatch ".Tests.ps1" }
foreach ($function in $functions)
{
. $function.FullName
}
- Should I use Install-Module rather than Import-Module?
- Maybe I need to import the module for each powershell task rather than attempting to load it once and reference many times?
Any help would be much appreciated.





tree "C:\Program Files\WindowsPowerShell\Modules" /F /A? It is one of the path of$PSModulePath. Could you specify your steps/script to get the custom module files?