Passing Environment variable from Jenkins to CTP job

Currently, we setup individual CTP jobs for various environments, but I was wondering if it would be possible to setup a single job in CTP, and then pass the env Variable Set based on the jenkins job (script or cmd line) rather an defining individual builds within CTP?

Answers

  • Matt LoveMatt Love Posts: 57 admin

    It's a very good idea, but today neither the REST API in CTP nor the Parasoft plug-in for Jenkins support executing a single job against different variable set environments. We may consider it for a future enhancement.

  • goofy78270goofy78270 Posts: 127

    Is it possible to pass in a single variable in a request from Jenkins, to override one within the Variable Set, such as ENV or BASEURL, in the image above?

  • goofy78270goofy78270 Posts: 127
    edited July 29

    Also, wondering if this is still valid since the variable sets are actually environments
    https://forums.parasoft.com/discussion/3864/using-rest-to-call-soatest

    Is there documentation for this endpoint, if it is still valid?

  • goofy78270goofy78270 Posts: 127
    edited July 29

    I found that the latest api version is 6, as well as a relevant curl, but unsure what fields may be required versus optional. We would like to mimic the call from Jenkins, with a simple environment difference, if possible.

    curl -X POST "http://...:8080/soavirt/api/v6/testExecutions" -H  "accept: application/json" -H  "Authorization: Basic ..." -H  "Content-Type: application/json" -d "{\"general\":{\"config\":\"\",\"nobuild\":true,\"publish\":true,\"showdetails\":true},\"scopeOptions\":{\"workspace\":{\"excludes\":[\"string\"],\"includes\":[\"string\"],\"resources\":[\"string\"],\"workItems\":[\"string\"]}},\"soatestOptions\":{\"dataGroupConfig\":{\"dataGroupTests\":[{\"dataGroups\":[{\"activeDataSource\":\"\",\"name\":\"\"}],\"workspacePath\":\"\"}]},\"dataSource\":{\"dataSourceName\":\"\",\"dataSourceRow\":\"\"},\"environment\":\"\",\"environmentConfig\":{\"environmentTests\":[{\"environment\":{\"variables\":[{\"name\":\"\",\"value\":\"\"}]},\"workspacePath\":\"\"}]},\"router\":{\"matchWhole\":true,\"replaceUri\":\"\",\"searchUri\":\"\"},\"testNames\":[{\"dataSourceName\":\"\",\"dataSourceRow\":1,\"match\":true,\"value\":\"account_hc.tst\"}]}}"
    
  • Matt LoveMatt Love Posts: 57 admin

    The soavirt/api/v6 API that you found is for making calls to SOAtest directly, which will bypass the job in CTP. You can instead look at GET/PUT "http://...:8080/em/api/v2/jobs/{jobId}" which will let you change the variable set and even the individual variables defined in the job. After saving changes via PUT you can run the job from Jenkins as you normally do.

  • goofy78270goofy78270 Posts: 127

    is there a separate license to hit .../em/api/... versus .../soavirt/api/...? When I try and hit em/api, I get the following error

    The number of licensed hits per day has been reached.  Use a license with a higher limit, or wait until tomorrow when the per day limit has been reset to process additional requests.
    
  • Matt LoveMatt Love Posts: 57 admin

    CTP is a different server from SOAtest. Use the host and port from your browser address bar in your "Test Scenarios" screenshot above. Also there is interactive REST API documentation at http://...:8080/em/apidoc that can help you try working with Jobs.

  • goofy78270goofy78270 Posts: 127

    Thank you for the help thus far...I feel like I am getting closer to the desired outcome.

    Currently, while I can update job, I am wondering if this is valid, or if I would need to include more info, like the specific variables for the variable set, in the POST

    POST to update variableset:

    {
      "testScenarioInstances": [
        {
          "testScenarioId": 2813,
          "variableSet": "DEV",
          "id": 41941
        }
      ]
    }
    

    Response for job

    {
      "context": {},
      "fork": false,
      "id": 1636,
      "name": "account-qa-hc",
      "testConfiguration": "",
      "testScenarioInstances": [
        {
          "dataGroups": [],
          "id": 56432,
          "priority": 0,
          "testScenarioId": 2813,
          "variableSet": "DEV",
          "variables": []
        }
      ]
    }
    

    before update

        {
          "context": {},
          "fork": false,
          "id": 1636,
          "name": "account-qa-hc",
          "testConfiguration": "",
          "testScenarioInstances": [
            {
              "dataGroups": [
                {
                  "active": "${dataSourceEnv}",
                  "id": "ds_636953065_1588266343265_273573173"
                }
              ],
              "id": 41941,
              "priority": 0,
              "testScenarioId": 2813,
              "variableSet": "QA",
              "variables": [
                {
                  "key": "baseUrl",
                  "type": "active"
                },
                {
                  "key": "baseUrlAccount",
                  "type": "active"
                },
                {
                  "key": "baseUrlAuthN",
                  "type": "active"
                },
                {
                  "key": "baseUrlSession",
                  "type": "active"
                },
                {
                  "key": "dataSourceEnv",
                  "type": "active"
                },
                {
                  "key": "env_Auth_Password",
                  "type": "active"
                },
                {
                  "key": "env_Auth_Username",
                  "type": "active"
                }
              ]
            }
          ]
        },
    
Sign In or Register to comment.