< Back

Invoke-JenkinsCommand

Wed Jan 15, 2020 10:35 am

NAME Invoke-JenkinsCommand



SYNOPSIS

Execute a Jenkins command or request via the Jenkins Rest API.





SYNTAX

Invoke-JenkinsCommand [[-ContentType] <String>] [[-Body] <Object>] [-Uri] <String> [[-Credential] <PSCredential>]

[[-Crumb] <String>] [[-Type] <String>] [[-Api] <String>] [-Command] <String> [[-Method] <String>] [[-Headers]

<Hashtable>] [<CommonParameters>]





DESCRIPTION

This cmdlet is used to issue a command or request to a Jenkins Master via the Rest API.





PARAMETERS

-Uri <String>

Contains the Uri to the Jenkins Master server to execute the command on.



Required? true

Position? 2

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Credential <PSCredential>

Contains the credentials to use to authenticate with the Jenkins Master server.



Required? false

Position? 3

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Crumb <String>

Contains a Crumb to pass to the Jenkins Master Server if CSRF is enabled.



Required? false

Position? 4

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Type <String>

The type of endpoint to invoke the command on. Can be set to: Rest,Command.



Required? false

Position? 5

Default value Rest

Accept pipeline input? False

Accept wildcard characters? false



-Api <String>

The API to use. Only used if type is 'rest'. Can be XML, JSON or Python. Defaults to JSON.



Required? false

Position? 6

Default value Json

Accept pipeline input? False

Accept wildcard characters? false



-Command <String>

This is the command and any other URI parameters that need to be passed to the API. Should always be set if

the Type is set to Command.



Required? true

Position? 7

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Method <String>

The method of the web request to use. Defaults to default for the type of command.



Required? false

Position? 8

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Headers <Hashtable>

Allows additional header values to be specified.



Required? false

Position? 9

Default value @{}

Accept pipeline input? False

Accept wildcard characters? false



-ContentType <String>

{{Fill ContentType Description}}



Required? false

Position? 10

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Body <Object>

{{Fill Body Description}}



Required? false

Position? 11

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

The result of the Api as a string.







NOTES









-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Invoke-JenkinsCommand `

-Uri 'https://jenkins.contoso.com' \\`

-Credential (Get-Credential) \\`

-Crumb $Crumb \\`

-Api 'json' \\`

-Command 'job/MuleTest/build'



Triggers the MuleTest job on https://jenkins.contoso.com to run using the credentials provided by the user.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Invoke-JenkinsCommand `

-Uri 'https://jenkins.contoso.com' \\`

-Credential (Get-Credential) \\`

-Api 'json'



Returns the list of jobs in the root of the https://jenkins.contoso.com using credentials provided by the user.

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Invoke-JenkinsCommand `

-Uri 'https://jenkins.contoso.com'



Returns the list of jobs in the root of the https://jenkins.contoso.com using no credentials for authorization.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Invoke-JenkinsCommand `

-Uri 'https://jenkins.contoso.com' \\`

-Credential (Get-Credential) \\`

-Type 'Command' \\`

-Command 'job/Build My App/config.xml'



Returns the job config XML for the 'Build My App' job in https://jenkins.contoso.com using credentials provided by

the user.



RELATED LINKS