TestProject Forum

How to launch several jobs sequentially with API?

I have 2 test jobs, the first on the iOS app and the second on the web application.
I need to run the iOS test job and if it goes correctly, I must run the web application test job.
My problem is that although I use the sequential workflow on CircleCI, the two test jobs are launched almost in parallel.

I think I need to get the status of first execution back and if it’s passed I run the second job, but unfortunately I don’t know how to do this.

Is there someone who can help me solve this problem please?

how to launch several jobs sequentially with API?

I have 2 test jobs, the first on the iOS app and the second on the web application.
I need to run the iOS test job and if it goes correctly, I must run the web application test job.
My problem is that although I use the sequential workflow on CircleCI, the two test jobs are launched almost in parallel.

I think I need to get the status of first execution back and if it’s passed I run the second job, but unfortunately I don’t know how to do this.

Is there someone who can help me solve this problem please?

My config.yml in CicrleCI :

version: 2.1

orbs:
  python: circleci/python@0.2.1
jobs:
  build-env:
    executor: python / default
    steps:
      - checkout
  run-iOS-tests:
    executor: python / default
    steps:
     - run:
          command: curl -X POST "https://api.testproject.io/v2/projects/MyProject/jobs/MyJobiOS/run" -H "accept: application / json" -H "Authorization: Y-MyAuthorization" -H " Content-Type: application / json "-d" {} "
          name: Run On iOS
     - checkout
  run-web-tests:
    executor: python / default
    steps:
      - run:
          command: curl -X POST "https://api.testproject.io/v2/projects/MyProject/jobs/MyJobWeb/run" -H "accept: application / json" -H "Authorization: Y-MyAuthorization" -H " Content-Type: application / json "-d" {} "
          name: Run Test On web
      - checkout
workflows:
  version: 2
  cross-Platf-testProject:
    jobs:
      - build-env
      - run-iOS-tests
      - run-web-tests:
          requires:
            - run-iOS-tests

Thanks in advance :pray:

Hi @walidTN,
As talked over the chat
run the command of run job and wait until it finishes please follow this on the commend stage at the config.yml file in circle ci

of course change the project id job id and api key.

this is to wait until execution finish so need to do twice in your case

-|

id=$(curl -X POST "https://api.testproject.io/v2/projects/{YourProjectID}/jobs/{YourJobID}/run" -H "accept: application/json" -H "Authorization: {YourAPIKey}>
id=$(echo $id | grep -i id* | awk -F '"' '{print $4}')
stateApi=$(printf "https://api.testproject.io/v2/projects/{YourProjectID}/jobs/{YourJobID}/executions/%s/state" "$id")
state=$(curl -X GET $stateApi -H "accept: application/json" -H "Authorization: {YourAPIKey}")
state=$(echo $state | grep -i state* | awk -F '"' '{print $4}')
while [ "$state" == "Executing" ]
do
 sleep 5
 state=$(curl -X GET $stateApi -H "accept: application/json" -H "Authorization: {YourAPIKey}")
 state=$(echo $state | grep -i state* | awk -F '"' '{print $4}')
done

Hi @Tal.Efraim,

It works :tada:

Thanks again Tal :pray: