r/PowerShell • u/Sunsparc • Aug 19 '26
Question Best practices for deploying code onto production server.
Historically, I have done Powershell code development directly on the server I'm running the scripts on and "live fire" tested them in production. Changes are GIT committed locally and then pushed to an Azure DevOps server in a repo I have set up solely for my Powershell scripts.
I'd like to get away from that because we're introducing Claude CLI so I would need to develop on my local machine instead.
Would a simple GIT push to the repo and then pull on the server suffice? Is there a better way?
17
Upvotes
11
u/SarcasticFluency Aug 19 '26 edited Aug 19 '26
You could always do what I did yesterday and deploy a script update to 13 servers with a bug that created a boot loop so fast that I had trouble undoing it for almost two hours.
7
u/DeusExMaChino Aug 19 '26
You can install an agent on the server and run a pipeline to copy changes to the server when you commit to main from your dev machine, so prod is only ever prod
2
u/FeleaseRpseineEiles Aug 19 '26
I use azure automation and have it's source control hooked into the github repo(devops works too)
It pulls changes. The runbooks need to have a hybrid group setup for them to be pushed out to servers otherwise works great. For endpoints I use action1
1
u/Federal_Ad2455 Aug 19 '26
This is how I am doing the deployment to AD https://github.com/ztrhgf/Powershell_CICD_repository
1
u/pdbress Aug 19 '26
We host our own private PS repository. It’s nice… so in the code repo, build a ci/cd pipeline so that any changes to main build a current release version of your ps module. Any non-main changes build a dev version of your module. Both situations build a new ps module that is version but only the production one is tagged as release. To test your, just install-module -name <something> -requiredversion <my release or dev version> from your private ps repository on the machine that needs the stuff. You’re going to want to get away from live testing in production. Ask me how I know 😫.
1
u/AdeelAutomates Aug 19 '26 edited Aug 19 '26
We use Azure's automation account as our production space to run scripts.
PowerShell scripts sit inside as 'runbooks'.
Its source controlled so you can link GitHub or Azure DevOps to it.
In terms of workflow.
We use hybrid workers (servers) as our compute for automation account so they can traverse the network (to get to services behind private endpoints and also reach our on prem network to perform tasks there).
To us actual servers are cattle not pets.
1
u/AGsec Aug 19 '26
I like github agents simply because I am most familiar with them, and you can do lots of linting tests to ensure things are deployed safely and according to policy. You can customize guardrails. I haven't explored many other ways to do it, but i'd imagine any CI/CD tool will give you the same general workflow and benefits.
1
u/Fallingdamage Aug 19 '26
I have PS automations that run on my server. I dont GIT anything. All the code that runs on the server remains on the server.
1
u/purplemonkeymad Aug 19 '26
Since you are using devops already, then you can create an artifact using Publish-Module (although i find Publish-PsResource more reliable for this.) Then you can add the artifact feed as a Powershell repository and can update the module from the feed.
Pretty sure you can automate everything except the pull using pipelines too.
1
u/ExceptionEX Aug 20 '26
You can set up dev test local then push from local git to devops for test/production deployment.
1
u/Agile_Seer Aug 22 '26
I keep all my PowerShell code in GitLab, and my deployments run through GitLab CI/CD. Each production server has a GitLab runner installed, so whenever I push changes to the repo, the pipeline handles the deployment automatically. That way I can develop and test locally, commit to GitLab, and let the pipeline push the updated code to the servers without touching production directly.
1
u/CyberChevalier Aug 25 '26
Module on a file psrepo
Sources on a git repo with a pipeline to push the nupkg to the PSrepo once validated
A task to update module from the repo on the fly