PowerShell module for interacting with a CloudBees Jenkins server using the Jenkins Rest API.
Branch | Azure Pipelines | Automated Tests | Code Quality |
---|---|---|---|
main |
This module requires the following:
If Windows Management Framework 5.0 or above is installed or the PowerShell Package management module is available:
The easiest way to download and install the Jenkins module is using PowerShell Get to download it from the PowerShell Gallery:
Install-Module -Name Jenkins
If Windows Management Framework 5.0 or above is not available and the PowerShell Package management module is not available:
Unzip the file containing this Module to your c:\Program Files\WindowsPowerShell\Modules
folder.
This PowerShell module is automatically tested and validated to run on the following systems:
This module should function correctly on other systems and configurations but is not automatically tested with them in every change.
This project contains automated integration tests that use Docker to run a Jenkins master server in a Docker Linux container. These tests can run on Windows 10 with Docker for Windows 2.0.4 or above installed. The tests also run automatically in Travis CI in the Linux build.
If a Jenkins Server has the CSRF setting enabled, then a "Crumb" will
first need to be obtained and passed to each subsequent call to Jenkins
in the Crumb parameter.
If you receive errors regarding crumbs then your Jenkins Server has CSRF
enabled and you will to ensure you are passing a valid "Crumb" obtained
by calling the Get-JenkinsCrumb
cmdlet.
To work with a Jenkins Master that has CSRF enabled:
$Crumb = Get-JenkinsCrumb `
-Uri 'https://jenkins.contoso.com' `
-Credential $Credential
New-JenkinsFolder `
-Uri 'https://jenkins.contoso.com' `
-Credential $Credential `
-Crumb $Crumb `
-Name 'Management' `
-Verbose
The full details of the cmdlets contained in this module can also be found in the wiki.
Disable-JenkinsJob
: Disables a Jenkins job.Enable-JenkinsJob
: Enables a Jenkins job.Get-JenkinsCrumb
: Gets a Jenkins Crumb.Get-JenkinsFolderList
: Get a list of folders in a Jenkins master server.Get-JenkinsJob
: Get a Jenkins Job Definition.Get-JenkinsJobList
: Get a list of jobs in a Jenkins master server.Get-JenkinsObject
: Get a list of objects in a Jenkins master server.Get-JenkinsPluginsList
: Retrieves a list of installed plugins.Get-JenkinsViewList
: Get a list of views in a Jenkins master server.Initialize-JenkinsUpdateCache
: Creates or updates a local Jenkins Update cache.Invoke-JenkinsCommand
: Execute a Jenkins command or request via the Jenkins Rest API.Invoke-JenkinsJob
: Run a parameterized or non-parameterized Jenkins Job.Invoke-JenkinsJobReload
: Reloads a job config on a given URL.New-JenkinsFolder
: Create a new Jenkins Folder.New-JenkinsJob
: Create a new Jenkins Job.Remove-JenkinsJob
: Remove an existing Jenkins Job.Rename-JenkinsJob
: Rename an existing Jenkins Job.Set-JenkinsJob
: Set a Jenkins Job definition.Test-JenkinsFolder
: Determines if a Jenkins Folder exists.Test-JenkinsJob
: Determines if a Jenkins Job exists.Test-JenkinsView
: Determines if a Jenkins View exists.Import-Module -Name Jenkins
$Crumb = Get-JenkinsCrumb `
-Uri 'https://jenkins.contoso.com' `
-Credential $Credential
Import-Module -Name Jenkins
$Jobs = Get-JenkinsJobList `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential)
Import-Module -Name Jenkins
$Jobs = Get-JenkinsJobList `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Folder 'Misc'
Import-Module -Name Jenkins
$Jobs = Get-JenkinsJobList `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-IncludeClass 'hudson.model.FreeStyleProject'
Import-Module -Name Jenkins
$Folders = Get-JenkinsFolderList `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential)
Import-Module -Name Jenkins
$MyAppBuildConfig = Get-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build'
Import-Module -Name Jenkins
Set-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build' `
-XML $MyAppBuildConfig
Import-Module -Name Jenkins
if (Test-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build') {
# ... Jenkins Job was found
}
Import-Module -Name Jenkins
New-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build' `
-XML $MyAppBuildConfig
Import-Module -Name Jenkins
Rename-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build'
-NewName 'Other Build'
Import-Module -Name Jenkins
Remove-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build'
Import-Module -Name Jenkins
Invoke-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build'
Import-Module -Name Jenkins
Invoke-JenkinsJob `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Name 'My App Build' `
-Parameters @{ verbosity = 'full'; buildtitle = 'test build' }
$Plugins = Get-JenkinsPluginsList `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Verbose
Invoke-JenkinsJobReload `
-Uri 'https://jenkins.contoso.com' `
-Credential (Get-Credential) `
-Verbose
Triggers a reload of the jenkins server 'https://jenkins.contoso.com'
For further examples, please see module help for individual cmdlets.