Skip to content

Instantly share code, notes, and snippets.

View goyalmohit's full-sized avatar

mohit goyal goyalmohit

View GitHub Profile
Write-Output 'Understand how $PreferenceVariable controls verbose output'
# prints current value of $verbosepreference
Write-Host "VerbosePreference is set to: $VerbosePreference"
# understanding how $VerbosePreference controls the verbose output
# case 1: set to bypass verbose stream
$VerbosePreference = "SilentlyContinue"
Write-Host "VerbosePreference is set to: $VerbosePreference"
Write-Verbose -message "This line will not be shown"
# Sample pipeline code to demonstrate scheduling using cron syntax
pool:
name: 'Hosted Ubuntu 1604'
schedules:
- cron: "0 * * * *"
displayName: "hourly build"
branches:
include:
schedules:
- cron: string # cron syntax defining a schedule
displayName: string # friendly name given to a specific schedule
branches:
# include is calculated first followed by exclude
# there is no implicit include
include: [ string ] # which branches the schedule applies to
exclude: [ string ] # which branches to exclude from the schedule
always: boolean # whether to always run the pipeline or only if there have been source code changes since the last run. The default is false.
Function Get-PersonDetails {
Begin {
Write-Verbose "In Begin Block: Get-PersonDetails"
[hashtable] $PersonDetails = @{}
}
Process{
Write-Verbose "In Process Block: Get-PersonDetails"
$PersonDetails = @{Keith=29; Eddy=24; Kevin=23; Kate=15}
}
End{
Function Get-PersonDetails {
Begin {
Write-Verbose "In Begin Block: Get-PersonDetails"
$PersonName = @()
$PersonAge = @()
}
Process{
Write-Verbose "In Process Block: Get-PersonDetails"
$PersonName = "Keith", "Eddy", "Kevin", "Kate"
$PersonAge = 29, 34, 23, 15
Function Get-PersonDetails {
Begin {
Write-Verbose "In Begin Block: Get-PersonDetails"
$PersonName = @()
$PersonAge = @()
}
Process{
Write-Verbose "In Process Block: Get-PersonDetails"
$PersonName = "Keith", "Eddy", "Kevin", "Kate"
$PersonAge = 29, 34, 23, 15
Function Get-Sum {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[int] $Number1,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[int] $Number2
# this is inline code
env | sort
# code trimmed for brevity from azure-pipelines.yml
...
steps: # 'Steps' section is to be used inside 'job' section.
- task: Bash@3
inputs:
targetType: 'inline'
script: 'env | sort'
...
@goyalmohit
goyalmohit / pre-receive.py
Created April 14, 2019 14:15
pre-receive git hook in python script to print incoming refs
#!/usr/bin/env python
import sys
import fileinput
# Read in each ref that the user is trying to update
for line in fileinput.input():
print "pre-receive: Trying to push ref: %s" % line
sys.exit(0)