Postman Test Automation with Jenkins
Install Docker
Install jenkins
install postman cli
install newman
Open Jenkins >install suggested plugins >create admin user
New item >name>freestyle job >Build steps >execute shell
>postman --version
>postman login --with-api-key {{postman-api-key-here}}
>postman collection run 17978790-88a0da8f-3459-4f51-85ec-b4737418a1
//newman --version >save
Run
ctrl+c : to exit
Managing secrets in Jenkins
Manage Jenkins >Credentials>System>Global Credentials>Postman Api Key
Using Postman CLI in Jenkins with Jenkins File
New item > Pipeline >ok
Go to pipeline configuration
Go to postman >Run collection >Automate Run via CLI>Run on CI/CD >Configuration command
>copy configuration from postman (that can be used as script in pipeline)
Go back to jenkins pipeline>paste the script
To define variable
environment{
POSTMAN_API_KEY = credentials("postman-api-key")
}
Using Newman in jenkins (Freestyle)
New item >name>freestyle job >Build steps >execute shell
>newman --version
>newman run https://api.postman.com/collections/17978790-e8c27790-4bf8-455b-bb90-4b5c1c424c02?apikey=PMAK-656ac7d835341966d37ff0f9-c69b28b1075a764deb10584ea0b61
Use api key as secret key in command for that
go to use secret text or file
Variable: POSTMAN_API_KEY
Credentials : postman-api-key
>newman run "https://api.postman.com/collections/17978790-e8c27790-4bf8-455b-bb90-4b5c1c424c02?apikey=$POSTMAN_API_KEY"
Using Newman in jenkins (Jenkins file)
New item > Pipeline >ok
Go to pipeline configuration
Pipeline script :
pipeline{
agent any
environment{
POSTMAN_API_KEY = credentials("postman-api-key")
}
stages{
stage(Running collection){
steps{
sh newman --version
sh newman run "https://api.postman.com/collections/17978790-e8c27790-4bf8-455b-bb90-4b5c1c424c02?apikey=$POSTMAN_API_KEY"
}}}}
Comments
Post a Comment