Jenkins email send remote server cucumber report

Viewed 782

I have a requirement let me explain scenario,

  • Their is COMPUTER-A (Jenkins Server) through which we triggered pipeline build
  • First Step it will create VM (COMPUTER-B) in vlab machine and get the IP
  • Second Step it will execute testsuites.sh in COMPUTER-B through ssh below is pseudo-code

    steps {
      script {
        sh """
          ssh -i id_rsa -o StrictHostKeyChecking=no ${USER}@${env.IP} "nohup /home/testsuites.sh > foo.out 2> foo.err < /dev/null & "
        """
      }
    }
    

    this script is run in background "mvn clean test" which will run all test case and generate cucumber report at the end of build.

    till this working fine.

    Since its run in background jenkins job will not going to wait & will move to next stage

  • Third Step Jenkins Server COMPUTER-A will send success mail

Now the requirement is once the build is success i need to send the cucumber test report through another mail. How to notify the jenkins job in COMPUTER-A (Since its already completed) to sent mail with cucumber report file which is their in remote server COMPUTER-B.

i can run corn job to check for build success , but how to notify the jenkins to send email with the cucumber test report.

2 Answers

What you need is Quiet Period

node {
    build job: 'FetchCucumberReport',
          quietPeriod: 60,// in secs -->1min
          wait: false
}

So what the above code does is it will trigger FetchCucumberReport Job after a 1 minute. If you roughly know how long the test cases will take to complete all tasks ( lets say 4 hours) then set quietPeriod:14400(seconds) and it will trigger the build after 4 hours.

UPDATED
You will have to look into API calls https://wiki.jenkins.io/display/JENKINS/Remote+access+API

An e.g

curl -X POST -u user:password http://localhost:8080/job/FetchCucumberReport/build

Hope it helps :)

You could trigger a build as soon as your long running job is finished, which just emails the results:

curl -X POST http://user:password@<jenkins-url>:8080/job/test/build

If the job can run on the same machine it should be easy to gather the results, if not, you could just copy the artifacts via scp.

But I think that another approach might be better suited for your problem. Just let the job run as long as it takes, then you can send the email afterwards much easier. If you would like to trigger another job before, you could trigger another job which runs on the same machine.

Maybe creating a temporary jenkins slave might be the best idea. You can also do this via the REST API: Creating-node-with-the-REST-API

Related