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
595 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,280 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,810 points
226 views
0 votes
1 answer
0 votes
1 answer
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
124 views
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,280 points
56 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,280 points
649 views