Running PowerShell scripts using Jenkins
Jenkins:
Jenkins has been primarily used for automating jobs and tasks on Linux servers. In this blog, we will be configuring Jenkins to execute Power Shell scripts on Windows. This blog will not be covering Jenkins server set up steps on Windows.
PowerShell Plugin:
Jenkins PowerShell plugin is a useful tool for running Power Shell scripts on Windows servers via Jenkins.
Plugin installation:
· Login to Jenkins and navigate to Manage Jenkins > Manage Plugins.
· Click on the Available tab and Enter PowerShell in the filter box.
· Select the plugin showing by name PowerShell Plugin.
· Download now and install after a restart.
The PowerShell plugin is now installed.
Now, let’s create a job on Jenkins as steps mentioned below:
· On Jenkins interface, click New Item
· Enter Create File for the job name. Select Freestyle project
· Again, Click the Add Parameter list and select Choice Parameter. Enter the options on new lines inside the Choices text box. Also, provide description for the options mentioned:
Tick This build is parameterized. Expand the Add Parameter list and choose String Parameter name has given Filename.
Expand the Add Parameter list and choose String Parameter name has given message.
Click on save the project.
The Job has been created.
Running the Job:
Go to the Jenkins home page and execute the job just created. Executing the job will bring a form with the options provided in the parameters specified as in the image below:
Now click on Build.
That’s it. Once the job is complete. A new file named First File gets created in C:\temp with content as This is a message from Jenkins.