• Stars
    star
    215
  • Rank 183,925 (Top 4 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Helper functions for PowerShell CI/CD scenarios

Build status

BuildHelpers

This is a quick and dirty PowerShell module with a variety of helper functions for PowerShell CI/CD scenarios.

Many of our build scripts explicitly reference build-system-specific features. We might rely on $ENV:APPVEYOR_REPO_BRANCH to know which branch we're in, for example.

This certainly works, but we can enable more portable build scripts by bundling up helper functions, normalizing build variables, and avoiding build-system-specific features.

Pull requests and other contributions welcome!

Instructions

# One time setup
    # Download the repository
    # Unblock the zip
    # Extract the BuildHelpers folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)

    #Simple alternative, if you have PowerShell 5, or the PowerShellGet module:
        Install-Module BuildHelpers

# Import the module.
    Import-Module BuildHelpers

# Get commands in the module
    Get-Command -Module BuildHelpers

# Get help
    Get-Help Get-BuildVariable -Full
    Get-Help about_BuildHelpers

Examples

Get Normalized Build Variables

Get-BuildVariable

# We assume you're in the project root. If not, specify a path:
Get-BuildVariable -Path C:\MyProjectRoot

Get Project Name

We occasionally need to reference the project or module name:

Get-ProjectName

This checks the following expected file system organizations, in order:

(1) File structure:

  • ProjectX (Repo root)
    • ProjectX (Project here)

Output: ProjectX

(2) File structure:

  • ProjectX (Repo root)
    • DifferentName (Project here. tsk tsk)
      • DifferentName.psd1

Output: DifferentName

(3) File structure:

  • ProjectX (Repo root)
    • ProjectX.psd1 (Please don't use this organization...)

Output: ProjectX

(5) File structure:

  • ProjectWhatever (Repo root)
    • src (or source)
      • ProjectX.psd1

Output: ProjectX

(6) File structure:

  • ProjectX
    • NoHelpfulIndicatorsOfProjectName.md

Output: ProjectX

Create Normalized Environment Variables

This runs a few commands from BuildHelpers module, and populates ENV:BH... variables

# Read the current environment, populate env vars
Set-BuildEnvironment

# Read back the env vars
Get-Item ENV:BH*

Here's an example, having run Set-BuildEnvironment in an AppVeyor project:

AppVeyor Example

Update your FunctionsToExport

During the module authoring process, updating FunctionsToExport can be tedious, so many folks leave this set to '*', missing out on module auto-loading and other benefits.

To get the best of both worlds, use FunctionsToExport='*', and use Set-ModuleFunction in your build before deployment:

# Set your build environment (we use this to get psd1 path)
Set-BuildEnvironment

# Check current FunctionsToExport:
Select-String -Path .\PSSlack\PSSlack.psd1 -Pattern FunctionsToExport

    # PSSlack\PSSlack.psd1:61:FunctionsToExport = '*'

# Update the psd1 with Set-ModuleFunction:
Set-ModuleFunction

# Check FunctionsToExport again:
Select-String -Path .\PSSlack\PSSlack.psd1 -Pattern FunctionsToExport

    # PSSlack\PSSlack.psd1:61:FunctionsToExport = @('Find-SlackMessage','Get-PSSlackConfig','Get-SlackChannel','Get-SlackHistory','Get-SlackUser','New-SlackField','New-SlackMessage','New-SlackMessageAttachment','Send-SlackApi','Send-SlackFile','Send-SlackMessage','Set-PSSlackConfig')

Update your ModuleVersion

Typical examples take an existing PSD1 file and bump the module version from that. Not so helpful if you don't commit that version to Git: The next time you bump the version, you're bumping the original version.

# Get the latest version for a project
$Version = Get-NextNugetPackageVersion -Name $env:BHProjectName

# Update the module metadata with the new version - thanks to Joel Bennett for this function!
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $Version

Notes

Thanks to Joel Bennett for the ConvertTo-Metadata function that we use in Set-ModuleFunction!

More Repositories

1

PowerShell

Various PowerShell functions and scripts
PowerShell
953
star
2

Invoke-Parallel

Speed up PowerShell with simplified multithreading
PowerShell
384
star
3

PSDeploy

Simple PowerShell based deployments
PowerShell
347
star
4

PSSQLite

PowerShell module to query SQLite databases
PowerShell
309
star
5

PSDepend

PowerShell Dependency Handler
PowerShell
282
star
6

PSSlack

PowerShell module for simple Slack integration
PowerShell
274
star
7

PSExcel

A simple Excel PowerShell module
PowerShell
245
star
8

SecretServer

Secret Server PowerShell Module
PowerShell
87
star
9

PSStackExchange

PowerShell module to query Stack Exchange API
PowerShell
81
star
10

PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
PowerShell
47
star
11

PSHTMLTable

PowerShell module to spice up ad hoc notifications and reports
PowerShell
38
star
12

Git-Presentation

Presentation materials for Git and GitHub TechSession
34
star
13

WritingModules

Material accompanying PowerShell + DevOps Summit session
PowerShell
32
star
14

PSDiskPart

DiskPart PowerShell Module
PowerShell
32
star
15

Infoblox

Infoblox PowerShell Module
PowerShell
30
star
16

PSNeo4j

Simple Neo4j PowerShell Wrapper
PowerShell
29
star
17

ADGrouper

Define dynamic AD security group membership via yaml
PowerShell
19
star
18

Dots

A janky, neo4j based CMDB glued together with PowerShell
PowerShell
16
star
19

Citrix.NetScaler

PowerShell module for working with Citrix NetScaler REST API
PowerShell
15
star
20

PSRT

PowerShell wrapper for Request Tracker
PowerShell
10
star
21

TireFire

A janky PowerShell module to simplify managing notes and their metadata
PowerShell
7
star
22

PSStash

Atlassian Stash PowerShell Module
PowerShell
7
star
23

PSPagerDuty

Simple PowerShell PagerDuty module
PowerShell
7
star
24

PSLDAPQueryLogging

PowerShell module to simplify configuring AD LDAP diagnostic logging
PowerShell
7
star
25

PSPuppetDB

Simple module for querying the PuppetDB API
PowerShell
6
star
26

CommunityLightningDemos2017

Proposals, and eventually demo material for Community Lightning Demos
PowerShell
6
star
27

Wait-Path

Wait for a path to exist
PowerShell
5
star
28

PSSensu

Simple PowerShell module for working with the Sensu Go API
PowerShell
3
star
29

RamblingCookieMonster.github.io

CSS
3
star
30

SessionMaterials

Materials or links to materials from sessions I've participated in
PowerShell
3
star
31

lisa-kitchen-demo

Example used for Test-Kitchen demo
PowerShell
2
star
32

AppVeyor-DSC-Test

POC to test DSC configurations on a fresh VM from AppVeyor
PowerShell
2
star
33

AppVReporting

App-V Reporting PowerShell Module
PowerShell
2
star
34

zAppVeyor-Explore

PowerShell
1
star
35

wip

Stuff that doesn't have a home yet
PowerShell
1
star