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
  get_url:
    url: "https://ci.contoso.com/job/NightlyBuild/lastSuccessfulBuild/artifact/NightlyBuild-345.tar.bz2"
    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 archive.zip 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,240 points
2,599 views

1 answer to this question.

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,300 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,890 points
2,345 views
0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
4,183 views
0 votes
1 answer

style.css not getting executed while installing lamp stack using ansible

Hey @Kishore make sure, your folder directory ...READ MORE

answered Feb 9, 2019 in Ansible by Monish
855 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
+2 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,300 points
868 views
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,300 points
5,626 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP