How to get the Docker image id used by a job?

247 views
Skip to first unread message

Don Jackson

unread,
May 30, 2018, 10:11:05 PM5/30/18
to Jenkins Users

I am using a Docker container/image in a pipeline script to build some artifacts.

I would like to record the Docker image id that was used for the job, and need to get this info from within the running job/container.

I installed the Docker Traceablity plugin, and now when I view a build in the web gui, I see the Docker Fingerprints option on the left column, I select that and a page appears that seems to have exactly the info I want.

How can I get that value programmatically?

I've looked at the api/json, and don't see it, and all attempts to create a URL that would give me this info as JSON have failed.

Any help/advice appreciated...

Thanks

Christian Gagneraud

unread,
May 30, 2018, 11:20:48 PM5/30/18
to jenkins...@googlegroups.com
On 31 May 2018 at 14:11, Don Jackson <d...@drivescale.com> wrote:
>
> I am using a Docker container/image in a pipeline script to build some
> artifacts.
>
> I would like to record the Docker image id that was used for the job, and
> need to get this info from within the running job/container.
>
> I installed the Docker Traceablity plugin, and now when I view a build in
> the web gui, I see the Docker Fingerprints option on the left column, I
> select that and a page appears that seems to have exactly the info I want.
>
> How can I get that value programmatically?

From a shell script i use:
id=$(basename $(cat /proc/self/cpuset))

Chris

>
> I've looked at the api/json, and don't see it, and all attempts to create a
> URL that would give me this info as JSON have failed.
>
> Any help/advice appreciated...
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/debd1037-c1b2-4f0b-a018-8a2a4e315c6b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Don Jackson

unread,
May 31, 2018, 1:29:52 PM5/31/18
to Jenkins Users


On Wednesday, May 30, 2018 at 8:20:48 PM UTC-7, Christian Gagneraud wrote:

>
> I would like to record the Docker image id that was used for the job, and
> need to get this info from within the running job/container.
>
> I installed the Docker Traceablity plugin, and now when I view a build in
> the web gui, I see the Docker Fingerprints option on the left column, I
> select that and a page appears that seems to have exactly the info I want.
>
> How can I get that value programmatically?

From a shell script i use:
id=$(basename $(cat /proc/self/cpuset))

Thanks!

If I am not mistaken, this gives me the CONTAINER id, and what I am really looking for is the IMAGE id, that is, the specific instance identifier of the Docker image used to build the job....

Is there a way to get from the Container ID to the Image ID?

Or get the image ID directly?

Christian Gagneraud

unread,
May 31, 2018, 7:20:23 PM5/31/18
to jenkins...@googlegroups.com
On 1 June 2018 at 05:29, Don Jackson <d...@drivescale.com> wrote:
>
>
> On Wednesday, May 30, 2018 at 8:20:48 PM UTC-7, Christian Gagneraud wrote:
>>
>>
>> >
>> > I would like to record the Docker image id that was used for the job,
>> > and
>> > need to get this info from within the running job/container.
>> >
>> > I installed the Docker Traceablity plugin, and now when I view a build
>> > in
>> > the web gui, I see the Docker Fingerprints option on the left column, I
>> > select that and a page appears that seems to have exactly the info I
>> > want.
>> >
>> > How can I get that value programmatically?
>>
>> From a shell script i use:
>> id=$(basename $(cat /proc/self/cpuset))
>
>
> Thanks!
>
> If I am not mistaken, this gives me the CONTAINER id, and what I am really

My mistake, this gives you the container ID, not the image ID.

> the Docker image used to build the job....
>
> Is there a way to get from the Container ID to the Image ID?
>
> Or get the image ID directly?

I don't know if Jenkins offers this service, and from within the
container, you would need to use "docker inspect".
If you're into python, checkout the docker python module:
http://docker-py.readthedocs.io/en/stable/index.html
If you bind mount /var/run/docker.sock in you container, then you can
access docker daemon.

Chris

>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/4e0f1af3-c5b9-409f-a166-49ddcf1b8dfc%40googlegroups.com.

ZillaYT

unread,
May 31, 2018, 9:08:11 PM5/31/18
to Jenkins Users
Try the idea I had in https://groups.google.com/forum/?nomobile=true#!topic/jenkinsci-users/BQILjucGZPM. I'm still trying to make it work, but maybe you'll get some traction and share.

Don Jackson

unread,
Jun 1, 2018, 8:07:56 PM6/1/18
to Jenkins Users


On Thursday, May 31, 2018 at 4:20:23 PM UTC-7, Christian Gagneraud wrote:

> Or get the image ID directly?

I don't know if Jenkins offers this service, and from within the
container, you would need to use "docker inspect".
If you're into python, checkout the docker python module:
http://docker-py.readthedocs.io/en/stable/index.html
If you bind mount /var/run/docker.sock in you container, then you can
access docker daemon.

With the Docker Traceability plugin installed, in the GUI of a specific build of a job, there is the Docker Fingerprints option in the left-hand side column:

And when I select that, I get this:


Which seems to have exactly the information I want.


I'm trying to find a way go access this data via the Jenkins API, to no avail.

If I could get it via the API, then I could make that same request inside my build job to get it as well.


I've spent several hours experimenting and web-searching, to no avail....


 
 

Lee Meador

unread,
Jun 11, 2018, 1:43:11 PM6/11/18
to Jenkins
This is really a Docker question and there are several Stack Overflow questions discussing it. Its not so straightforward but there are ways to query the host docker via socket once you figure out the ip and port.

A simple solution that might work. You can pass environment variables into the containter with the -e option on the "docker run" command line.

In scripted, use:

    docker.image('maven:3-alpine').inside('-e IMAGE=\'maven:3-alpine\'') {
Syntax is different for declarative where you use the 'args' tag.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1e436006-ab3c-4bd5-9052-23f6ab4ae7d0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-- Lee Meador
Sent from gmail. My real email address is lee AT leemeador.com
Reply all
Reply to author
Forward
0 new messages