0

jenkins pipeline-A

pipeline{
  stage('deploy'){
    agent { label 'slave' }
  steps{
    script{
      if [ "$deployenv" = dev ];
      then 
        echo 'restart not required'
      elif [ "$deployenv" = qa ];
      then
        echo "restart required"
        //need to invoke another jenkins pipeline-B here
      fi
    }
  }

1 Answer 1

0

Shell Command to Execute Build or Pipeline can be inserted into your Shell Script in Pipeline A, at the Point where you want to invoke the Pipeline B.

The Point where you want to trigger Pipeline B could use either "SSH" or "Curl" or "Java CLI Client" to use JENKINS API to control this.

With SSH:

ssh -l USERNAME -p JENKINSPORT SERVER COMMAND ## Pipeline B should be the COMMAND here  

[[ Initially, you have to enable the SSH Access and configure the Authentication ]]

Reference : https://www.jenkins.io/doc/book/managing/cli/#ssh

With Java CLI Client:

Download the Client via :

JENKINS_URL/jnlpJars/jenkins-cli.jar  

Execute via :

java -jar jenkins-cli.jar [-s JENKINS_URL] [global options...] command [command options...] [arguments...] ## Pipeline B should be the COMMAND here  

Reference : https://www.jenkins.io/doc/book/managing/cli/#using-the-cli-client

With Curl:

Something like this:

curl -X POST http://....:8080/job/....  

With username & credentials,

curl -X POST --user <jenkins_username>:<jenkins_API_key> http://<jenkins_server_url>/job/<your_jenkins_job_name>/build ## Pipeline B should be the COMMAND here  

Reference : https://myopswork.com/when-shell-scripts-meets-jenkins-61594f576e96

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .