How to store a string from console output to environmental variable?

I had a scenario where I have created a freestyle project and adding build steps. In build step 1 I am calling an API using HTTP request Plugin and in the console I am getting the token which I need to pass to build step 2.
Please help on this.

Thanks

Hello @Surath and welcome to this community :wave:

Why is the token written on the console?
Couldn’t you store it in a variable?
With the HTTP Request Plugin you get a response object which contains the status and the content.
I’m sure there are way better approaches, but my first thought was to store the token in a temporary file, and then read the file content in the next step.

Could we see your code?

1 Like

With freestyle you can’t really. There might be plugins to read a file from disk into a variable, so you could write your output of your command to a file first.

I would really recommend looking into pipeline. It not only has the advantage of having your job configuration as code which can be committed and versioned, but gives you way more flexibility that. The ironically named freestyle

1 Like

Hello @poddingue Thankyou for the response.
The problem here in build step1 I am calling API which will gives we the access_token and it’s printing on the console now I need to get the access_token string and store it variable how could I do that ?

1 Like

Thankyou @halkeye for quick response. I would like to use freestyle as requirement.

Hello @halkeye, is there a way to read a JSON file which is stored under the workspace directory in the project and get the value for a key and store it in the environmental variable so that I need to trigger another job using that variable?

1 Like

Hello @poddingue, is there a way to read a JSON file which is stored under the workspace directory in the project and get the value for a key and store it in the environmental variable so that I need to trigger another job using that variable?

1 Like

As I havnt used freestyle in 5+ years I really have nothing to offer. I think you’ll spend more time trying to work around freestyles limitations than you would learning pipeline.

2 Likes

If you were to write your API call in some Groovy code you could use a Groovy builder to do whatever you want with the returned token. Don’t believe anyone that tells you that ‘freestyle jobs’ have limitations. In my opinion, the only limitation is in people’s imagination. :wink: