This is a simple yet useful Azure DevOps set of tasks that allow to install and run Microsoft Bicep CLI commands in Azure Pipelines (cross-platform).
This task downloads and installs in the agent any version of the Bicep CLI available (adding it to the PATH environment variable). After running the task, the Run Bicep CLI build command task
can be used. Alternatively, bicep
command could be used in a script directly.
The tool is cached in the agent after download, so subsequent runs will be faster.
This task takes only one version
parameter input (semantic versioning) which is the version of Bicep to download.
steps:
- task: BicepInstall@0
inputs:
version: 0.3.1
This tasks runs the bicep build
command with an input path containing .bicep
file(s) (glob is supported). After running the task, the resulting .json
files are left in the same folder as the .bicep
file resides.
This task takes only one sourceDirectory
parameter input which is the path where the bicep file/files reside (can be a glob, directory, or a single file).
Note: When using a directory as sourceDirectory
, all files included in the directory will be processed (including files in subfolders). Same behaviour as specifying the directory with the glob wildcard **
. Example: ./bicep_files
would be interpreted as ./bicep_files/**
.
steps:
- task: BicepBuild@0
inputs:
process: 'multiple'
sourceDirectory: '.\bicep_files\*.bicep'
stdout: false # Note if stdout is true 'outputDirectory' will not be interpreted
outputDirectory: '.\bicep_files\out' # Only when 'stdout' is false or not defined
steps:
- task: BicepBuild@0
inputs:
process: 'single'
sourceFile: '.\bicep_files\sample1.bicep'
stdout: false # Note if stdout is true 'outputDirectory' will not be interpreted
outputFile: '.\bicep_files\sample1.out.json' # Only when 'stdout' is false or not defined and 'outputDirectory' is empty or not defined
Note: Bicep must be installed in the local machine. TypeScript must be also installed as a global package (npm i typescript -g
).
- Run
npm install
in the root directory. - Run
npm run build
in the root directory. - Define the needed agent environment parameters:
# For PowerShell:
$env:AGENT_TEMPDIRECTORY = "C:\TEMP" # Or any other existing directory
$env:AGENT_TOOLSDIRECTORY = "C:\tools" # Or any other existing directory
# For bash:
export AGENT_TEMPDIRECTORY="/temp" # Or any other existing directory
export AGENT_TOOLSDIRECTORY="/tools" # Or any other existing directory
- (Optional) Set variables for the tasks (as you want to test):
# For PowerShell:
$env:INPUT_VERSION = "0.3.1" # Or any other valid Bicep version
$env:INPUT_PROCESS = "multiple" # Selection between 'multiple' or 'single' file(s) processing
$env:INPUT_SOURCEDIRECTORY = "C:\bicep_files\*.bicep" # Or any other existing directory with bicep file(s)
$env:INPUT_SOURCEFILE = "C:\bicep_files\sample1.bicep" # Or any other existing bicep file
$env:INPUT_STDOUT = $false # To print the output to standard output (stdout) or not
$env:INPUT_OUTPUTDIRECTORY = "C:\bicep_files\out" # Or any other existing directory to store the json generated file(s)
$env:INPUT_OUTPUTFILE = "C:\bicep_files\sample1.out.json" # Or any other path/filename to store the generated file
# For bash:
export INPUT_VERSION="0.3.1" # Or any other valid Bicep version
export INPUT_PROCESS = "multiple" # Selection between 'multiple' or 'single' file(s) processing
export INPUT_SOURCEDIRECTORY="C:\bicep_files\*.bicep" # Or any other existing directory with bicep file(s)
export INPUT_SOURCEFILE = "C:\bicep_files\sample1.bicep" # Or any other existing bicep file
export INPUT_STDOUT = false # To print the output to standard output (stdout) or not
export INPUT_OUTPUTDIRECTORY = "C:\bicep_files\out" # Or any other existing directory to store the json generated file(s)
export INPUT_OUTPUTFILE = "C:\bicep_files\sample1.out.json" # Or any other path/filename to store the generated file
- Run
node src/install/index.js
andnode src/run/index.js
to execute the two tasks.
Note: the bicep_files
and the arm_templates
directories containing .bicep
and .json
files are only for development and testing purposes.
Feel free to open an issue or a PR if you want to without any problem :)
This project is licensed under the MIT License.
See the LICENSE file in the root of this repository.
The base logo for the tasks and the extension is property of the Microsoft Bicep project, used without any commercial purpose.