I know there is a remote access api: https://www.jenkins.io/doc/book/using/remote-access-api/
But is this API accessible via localhost and unauthenticated from inside a pipeline run? I say unauthenticated because it would be hit from inside a pipeline run so auth would not be required.
I tried doing curl -v http://localhost:8080/api from inside a pipeline run and got connect to 127.0.0.1 port 8080 failed: Connection refused.
I already use Jenkins functions like currentBuild.getBuildCauses() etc, but I'd much rather have my deploy scripts interrogate the api for this kind of info instead.
Is it possible to have a local, authenticated, endpoint for the Jenkins rest api (so I would not need a key or user to access it)?
short answer: you can not do actions with jenkins without auth info here
long answer:
mb some plugin has this functionality (i havent seen it)
to use curl for jenkins endpoint you need to use username:api or username/password token like this
curl http://<username>:<api-token>@<jenkins-server>/Jenkinsfile
in jenkins you can create user and password. Store this data in jenkins userpassword credentials and then use in pipeline withCreds()
if you need to create token
script can be different because of auth plugin
there are lot of examples in github
https://gist.github.com/wiz4host/17ab33e96f53d8e30389827fbf79852e https://gist.github.com/hayderimran7/50cb1244cc1e856873a4