How to Import a Custom PowerShell Module Into a Dockerfile 👨🍳
If you want to use a custom PowerShell module in a Docker container, the command to import it correctly is simple when you know it! 😋
2 min read
This post wouldn't have been possible without Jesse Chisholm, who last month gave me the solution below. Thanks Jesse! ❤
In one of my previous posts on linting PowerShell scripts, I wasn't impressed with how GitLab CI displays PSScriptAnalyzer logs. I ended my post by asking my readers if they know how we could improve the readability of logs and one reader, Jesse Chisholm, suggested I try the script below.
After trying it, it was exactly what I was looking for! 🤩
But, since I was using PSScriptAnalyzer with Docker, I didn't want to declare this function every time I called the analyzer... So I started looking for how to make it available in my Docker container. 🤔
After a while, I finally managed to install the function and make it available in the terminal with a PowerShell module. By adding it to the /usr/local/share/powershell/Modules folder, the module is automatically imported and every user who connects to the Docker container has access to the Show-LintMessages function! 🤗
In GitLab CI, I also had to pipe the output of PSScriptAnalyser to the new command.
Unfortunately, the message was truncated in the GitLab CI job output... 😓
So I tweaked the function a bit, and after a few tries, I finally ended with the script below.