Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-58865

Electric flow plugin does not return the json details of a REST call

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • electricflow-plugin
    • None

      Issue:
      I am trying to do a REST API call to create a electricflow job execution. When I run that REST call it will respond with a json of the ID for that execution and I want to parse that ID into a groovy variable

      Steps to resolve:
      From what I am seeing the `perform` method here: https://github.com/jenkinsci/electricflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/electricflow/ElectricFlowGenericRestApi.java#L68 does not return a value into a groovy variable. In my opinion it should be like `ReturnStdOut` on a shell step inside of a pipeline rather than just printing into the logs. This would allow other REST calls to check on the status the build using the ID which is returned

          [JENKINS-58865] Electric flow plugin does not return the json details of a REST call

          Alex Taylor added a comment -

          This could be done one of 3 ways:
          1. The Electric flow REST API function could be changed into a `Step` rather than implementing a `SimpleBuildStep` since the Simple build step does not allow for return values. This would mean writing a custom step which will send out the API call and then return the response from the Electric Flow server into a groovy variable
          2. This REST API could be converted into a block-scoped Step (or SimpleBuildWrapper) and then the response could be captured inside of an Environment variable which is able to be used later inside of the pipeline.
          3. https://issues.jenkins-ci.org/browse/JENKINS-29144 could be fixed and a SimpleBuildStep could be used to create the same environment variable in #2

          For 1 this would look like:

          def returnOut = step([$class: 'ElectricFlowGenericRestApi',
                      configuration: 'CBFConfiguration',
                      urlPath : '/projects',
                      httpMethod : 'POST',
                      body : '',
                      parameters : [
                          [$class: 'Pair',
                              key: 'projectName',
                              value: 'EC-TEST-Jenkins-1.00.00.01'
                          ],
                          [$class: 'Pair',
                              key: 'description',
                              value: 'Native Jenkins Test Project'
                          ]
                      ]
              ])
          

          and that returnOut would be a groovy variable and able to be used anywhere else

          For 2 and 3 there would be a general ENV variable called something like `REST_API_OUPUT` which is set on the return and then that can be used in the pipeline with `$env.REST_API_OUTPUT`

          Alex Taylor added a comment - This could be done one of 3 ways: 1. The Electric flow REST API function could be changed into a `Step` rather than implementing a `SimpleBuildStep` since the Simple build step does not allow for return values. This would mean writing a custom step which will send out the API call and then return the response from the Electric Flow server into a groovy variable 2. This REST API could be converted into a block-scoped Step (or SimpleBuildWrapper) and then the response could be captured inside of an Environment variable which is able to be used later inside of the pipeline. 3. https://issues.jenkins-ci.org/browse/JENKINS-29144 could be fixed and a SimpleBuildStep could be used to create the same environment variable in #2 For 1 this would look like: def returnOut = step([$class: 'ElectricFlowGenericRestApi' , configuration: 'CBFConfiguration' , urlPath : '/projects' , httpMethod : 'POST' , body : '', parameters : [ [$class: 'Pair' , key: 'projectName' , value: 'EC-TEST-Jenkins-1.00.00.01' ], [$class: 'Pair' , key: 'description' , value: 'Native Jenkins Test Project' ] ] ]) and that returnOut would be a groovy variable and able to be used anywhere else For 2 and 3 there would be a general ENV variable called something like `REST_API_OUPUT` which is set on the return and then that can be used in the pipeline with `$env.REST_API_OUTPUT`

          ataylor, thanks for the ticket, great suggestions and help on resolving the ticket!

          New version of the plugin 1.1.10 was released which includes new workflow step "Call REST API" where results can be stored within environment variable available during the build for scripted and declarative pipelines or can be returned from the function within scripted pipelines:

          https://wiki.jenkins.io/display/JENKINS/CloudBees+Flow+Plugin#CloudBeesFlowPlugin-CallRESTAPIofCloudBeesFlow.1

           

           

          Oleksii Vasylkivskyi added a comment - ataylor , thanks for the ticket, great suggestions and help on resolving the ticket! New version of the plugin 1.1.10 was released which includes new workflow step "Call REST API" where results can be stored within environment variable available during the build for scripted and declarative pipelines or can be returned from the function within scripted pipelines: https://wiki.jenkins.io/display/JENKINS/CloudBees+Flow+Plugin#CloudBeesFlowPlugin-CallRESTAPIofCloudBeesFlow.1    

          ElectricFlow ElectricCloud added a comment - fixed within v 1.1.10:  https://wiki.jenkins.io/display/JENKINS/CloudBees+Flow+Plugin#CloudBeesFlowPlugin-ReleaseNotes

            efpluginsdev ElectricFlow ElectricCloud
            ataylor Alex Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: