In my script, my goal is to get a list of tags associated with an image from dockerhub. Currently, I do that by getting an authentication token by doing the following
curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"$USERNAME\", \"password\": \"$PASSWORD\"}" https://hub.docker.com/v2/users/login/
I store the token in my Jenkins credentials and use it in my Groovy script as follows
curl -s -XGET -H 'Accept: application/json' -H 'Authorization: JWT $auth' https://hub.docker.com/v2/repositories/<REPO>/<IMAGE>/tags?page_size=1000 | jq -r '.results[].name'
The problem is that the token expires after one month (I didn't find any expiry related information in the offical docs) and I need to update the token in the Jenkins credentials after it expires.
The solution I think should work is to get the token at run time inside my script itself and use it directly. But because it will obtained every time at run time, I want the token to be alive for not more than 120 seconds.
Is there a way to set the time limit to the authentication token on dockerhub?