Getting numbered build artefact using ansible from jenkins

0 votes

I've got a jenkins server from which I download build artefacts. The job is set up in a way that the build artefact includes the job number like NightlyBuild-346.tar.bz2. The job number helps make it easy to know when the job was build. The problem is that I dont know the name of the file I'm downloading. I know I want the last successful build. I did something like this.

- name: download build from CI
    url: ""
    dest: /tmp/NightlyBuild-345.tar.bz2

But this breaks jenkins after the build finishes because the artefact becomes NightlyBuild-346.tar.bz2. The options that I have here are:

  • Try to use wildcards in the get_url module (not so sure about that)
  • Download ALL artifacts from the job (there are several) as a single and use command-line and regex magic to find the actual build artifact I care about. (potential for a hot unmaintanable mess)
  • Use the REST API to obtain the job number for the last successful job and form the full URL. (not sure that Ansible allows me to set variables on-the-fly like that).

Is there any better way to do this or are these my only options? In the end I'd like to publish to an artifactory repo from jenkins.

Aug 20, 2018 in Ansible by Atul
• 10,220 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can get the build number with uri module by querying jenkins:

- uri:
    url: http://ci/job/NightlyBuild/lastSuccessfulBuild/buildNumber
    return_content: yes
  register: build_number_resp

- debug: msg="URL with build number http://ci/job/NightlyBuild/lastSuccessfulBuild/artifact/NightlyBuild-{{ build_number_resp.content }}.tar.bz2"

answered Aug 20, 2018 by ajs3033
• 7,080 points

Related Questions In Ansible

+1 vote
1 answer

Ansible: Deleting matching IPs from hosts file using regex

Ansible notation isn't the same as YAML ...READ MORE

answered Jul 25, 2018 in Ansible by DareDev
• 6,670 points
0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

unable to build grails war on a vagrant machine using ansible

Try and run the command using shell ...READ MORE

answered Jul 2, 2018 in Ansible by ajs3033
• 7,080 points
0 votes
1 answer

When conditional not working in Ansible

Your identation is wrong and when is ...READ MORE

answered Apr 27, 2018 in Ansible by ajs3033
• 7,080 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.