1

We use the Puppetlabs VCSRepo to checkout a repository. When this is done, we would like to push a notification containing the SHA of the new version. I have no clue how to get this.

We use the VCS Repo like this:

vcsrepo { "/opt/ourcompany/distribution":
    ensure   => latest,
    owner    => $owner,
    provider => git,
    require  => [ Package["git"], User["ouruser" ]],
    source   => "git@domain.com:our/repository.git",
    revision => 'master',
    user => $owner,
}

Then we set-up a notification like this:

exec { "send-hipchat-message" :
   command => "curl -d \"$body\" $url", #Parameters are set somewhere else
   path => "/usr/bin/",
   subscribe => Vcsrepo["/opt/ourcompany/distribution"],
   refreshonly => true
}

So the question is: how do I get the SHA of the revision the vcs repo has just updated to?

Alex
  • 2,953
  • 1
  • 27
  • 37

1 Answers1

1

To just get SHA of latest commit you can use any of commands from another answer: How to retrieve the hash for the current commit in Git?

After that you just need to modify your command in exec to invoke something like git rev-parse HEAD from directory with sources. Here simple example:

exec { "send-hipchat-message" :
   command     => "echo \"SHA: $$(git rev-parse HEAD)\"",
   path        => "/usr/bin",
   subscribe   => Vcsrepo["/opt/ourcompany/distribution"],
   require     => Vcsrepo["/opt/ourcompany/distribution"],
   cwd         => '/opt/ourcompany/distribution',
   refreshonly => true
}

Note to cwd, require and command attributes.

Community
  • 1
  • 1
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69