Giter VIP home page Giter VIP logo

piraces / azure-devops-bicep-task Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 5.0 916 KB

Simple yet useful Azure DevOps set of tasks that allow to install and run Microsoft Bicep CLI commands in Azure Pipelines

Home Page: https://marketplace.visualstudio.com/items?itemName=piraces.bicep-tasks

License: MIT License

TypeScript 93.00% JavaScript 1.78% Bicep 5.22%
azure-devops azure-devops-extension azure-devops-pipelines azure-devops-extensions devops ci-cd bicep-cli bicep

azure-devops-bicep-task's Introduction

Azure DevOps Bicep Tasks

Node.js CI Build Status

Bicep Logo

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).

View in Marketplace

Install Bicep CLI task

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.

Sample YAML with the task

steps:
- task: BicepInstall@0
  inputs:
    version: 0.10.13

Run Bicep CLI build command task

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 or sourceFile 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/**.

Sample YAML with the task (for multiple 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

Sample YAML with the task (for single file)

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

Run Bicep CLI decompile command task

This tasks runs the bicep decompile command with an input path containing .json file(s) (glob is supported). After running the task, the resulting .bicep files are left in the same folder as the .json file resides.

This task takes only one sourceDirectory or sourceFile parameter input which is the path where the bicep file/files reside (can be a glob, directory, or a single file).

Note: Only files with .json extension will be processed.

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: ./arm_templates would be interpreted as ./arm_templates/**.

Sample YAML with the task (for multiple files)

steps:
- task: BicepDecompile@0
  inputs:
    process: 'multiple'
    sourceDirectory: '.\arm_templates\*.json'
    stdout: false # Note if stdout is true 'outputDirectory' will not be interpreted
    outputDirectory: '.\arm_templates\out' # Only when 'stdout' is false or not defined

Sample YAML with the task (for single file)

steps:
- task: BicepDecompile@0
  inputs:
    process: 'single'
    sourceFile: '.\arm_templates\arm_storage_account.json'
    stdout: false # Note if stdout is true 'outputDirectory' will not be interpreted
    outputFile: '.\arm_templates\sample1.out.bicep' # Only when 'stdout' is false or not defined and 'outputDirectory' is empty or not defined

Important notes

Starting on version 0.3 of the tasks, the user can specify an outputProcess input to choose the output option. The available options are:

  • default: Default (same name and directory as input files).
  • outDir: Selecting an output directory with the input outputDirectory.
  • outFile: Selecting an output file with the input outputFile.
  • stdout: Standard output (stdout).

Nevertheless, this option can be skipped and only specify the inputs outputDirectory, outputFile, stdout accordingly. Note that the inputs are exclusive. Do not specify multiple output options at once.

The order of preference of the inputs if outputProcess is not defined is the following:

  • stdout: if set to true.
  • outputFile: if set.
  • outputDirectory: if set.

If no input regarding output options is set, it will default to the source directory and source filename as output (only changing the extension).

Warnings handling

Starting with the patch 0.3.4, warnings in the build or decompilation processes will report a SucceededWithIssues status, showing all warnings in the pipeline execution.

Bicep versions support

Please consider using the latest version of the Bicep CLI, this extension does not ensure a correct execution with versions prior to 0.4.x.

Decompile command

Starting on version 0.3.7 of this extension, the decompile command will overwrite the destination file if it exists.

Local Development

Note: Bicep must be installed in the local machine. TypeScript must be also installed as a global package (npm i typescript -g).

  1. Run npm install in the root directory.
  2. Run npm run build in the root directory.
  3. 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
  1. (Optional) Set variables for the tasks (as you want to test):
# For PowerShell:
$env:INPUT_VERSION = "0.10.13" # 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.10.13" # 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
  1. Run node src/install/index.js and node 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.

Contributing

Feel free to open an issue or a PR if you want to without any problem :)

License

This project is licensed under the MIT License.

See the LICENSE file in the root of this repository.

Attributions

The base logo for the tasks and the extension is property of the Microsoft Bicep project, used without any commercial purpose.

azure-devops-bicep-task's People

Contributors

bm-andreww avatar dependabot[bot] avatar piraces avatar rpiraces-plain avatar svaenn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

azure-devops-bicep-task's Issues

Bicep build: is it possible to ignore Linter output that are 'Information level'

Hi,

I put in a linter file bicepconfig.json in my directory.

When I use the build task. In the build output I always see the following warning (so the build is indicated as partially succeeded).

##[warning]e:\b1\76\s\StorageAccount.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (e:\b1\76\s\bicepconfig.json).

This is a 'information' level.
Is there a way for the build to not report 'information' as a warning?

Thanks

bicep build issue

when I used the predefined variable as Output directory for .json generated by Bicep: $(build.artifactstagingdirectory) and Output filename for the .json generated file, but it looks like the $(build.artifactstagingdirectory) is ignore from the following logging of the execution command - so I could not locate where the rgdeploy.json is.

C:\hostedtoolcache\windows\bicep.exe\0.3.255\x64\bicep.exe build D:\a\1\s\SPI\SPIFuncApp.ResourceGroup\azuredeploy.bicep --outfile rgdeploy.json

Gettin access denied in bicep build task

I am using a classic release pipeline and have added the two tasks from the market place. The build task looks like this:

image

On the build task I am getting the following error:

2021-03-13T16:40:28.8175465Z ##[section]Starting: Run Bicep CLI build command
2021-03-13T16:40:28.8317177Z ==============================================================================
2021-03-13T16:40:28.8317572Z Task : Run Bicep CLI build command
2021-03-13T16:40:28.8317885Z Description : Run Bicep CLI build command
2021-03-13T16:40:28.8318130Z Version : 0.2.6
2021-03-13T16:40:28.8318376Z Author : Raúl Piracés
2021-03-13T16:40:28.8318667Z Help : Runs the Bicep CLI build command
2021-03-13T16:40:28.8319017Z ==============================================================================
2021-03-13T16:40:29.9440446Z Found tool in cache: bicep.exe 0.3.1 x64
2021-03-13T16:40:29.9445203Z [command]C:\hostedtoolcache\windows\bicep.exe\0.3.1\x64\bicep.exe build D:/a/r1/a/ --outdir D:\a\r1\a/
2021-03-13T16:40:31.0255473Z An error occurred reading file. Access to the path 'D:\a\r1\a' is denied.
2021-03-13T16:40:31.0311880Z ##[error]Failed to execute script. Related file: D:/a/r1/a/
2021-03-13T16:40:31.0369800Z ##[section]Finishing: Run Bicep CLI build command

Any ideas?

Latest version of bicep cli makes build task fail when using output directory

There's a new version of the bicep cli released, the new version is 0.10.13

If using this devops task with output directory option set, it fails with this message:

##[error]The version '0.10.13' of Bicep CLI does not support an output directory or an output file as an option... Consider upgrading to a latest version of the Bicep CLI.

In the task there's some code to check if the bicep cli version is < 0.3. This fails because the cli version is parsed as a number/float.
See here:

const bicepVersionNumber = Number.parseFloat(bicepToolVersion);
if (bicepVersionNumber < 0.3 && (outputProcess == OutputType.OutDir || outputProcess == OutputType.OutFile)) {

I suggest removing that piece of code altogether, or at least the parsing of the version number should be changed.

Number.parseFloat("0.10.13")
0.1

BicepBuild@0 Devops Task issue

Hello,
I am having an issue with the above task in Azure DevOps pipeline

Step look like this:
#Build all .bicep files into .json counterparts

steps:

  • task: BicepBuild@0
    inputs:
    sourceDirectory: '$(System.DefaultWorkingDirectory)/Infrastructure/Azure-Bicep-Deploy/BicepFiles/*.bicep'

The error from the pipeline is this:
image

The document says it is possible to build multiple files. So I am a bit stuck as what to do

Any help appreciated.

Andrew

How do I pass parameters to my bicep file in Azure DevOps

So excited Bicep is available in DevOps now.

I'm trying to mimic how my ARM template deployment works. I have 1 template and I pass parameters to it based on the service I am deploying and environment I am deploying to.

screen shot of ARM Template Deployment from DevOp
image

Version 0.3.7 does not find *.bicep files

Version 0.3.7 of BicepBuild does not find any *.bicep files in "multiple" mode.
The same yaml with version 0.3.4 is working.
Is that a know issue? Any workaround (except using 0.3.4 explicitly)?

This happens on Windows based agents

Request failed with status code 403

Bicep install often fails with a 403 from Azure DevOps pipeline:

Starting: BicepInstall
==============================================================================
Task         : Install Bicep CLI
Description  : Install Bicep CLI
Version      : 0.3.8
Author       : Raúl Piracés
Help         : Installs the Bicep CLI
==============================================================================
##[error][FATAL] Error while retrieving latest version tag: 'Request failed with status code 403'
Finishing: BicepInstall

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.