سؤال

I have a build promotion process modeled after this discussion (using promoted builds plugin.) In general, it works great. However, for a few "flavors" of the promotion process (not all) I'd like to push a git tag. I implemented this with an "execute shell" step as one of the promotion actions. This has been working well, and then today failed with the error below. I suspect I landed on a build slave where the workspace wasn't already initialized for git - and that I've been getting lucky in the past (using Cloudbees - where the build slaves are dynamically allocated.)

I've tried the "git publisher", but it seems to expect that you are in a setting where the git source plugin has already done its job. Has anyone been able reliably push a tag from a build promotion step ?

+ git checkout develop
fatal: Not a git repository (or any of the parent directories): .git
هل كانت مفيدة؟

المحلول 2

Disclaimer: I know nothing about Git.

You should never rely on files under ${WORKSPACE} when executing promotions. At best, they may be newer than the job run promotion that you are executing, and at worst the workspace could be empty while doing a new checkout (or non-existent as in your case). That's why in the discussion that you linked, I am using Copy Artifacts step. Note that that step copies from archived artifacts, not from job workspace, which should always be considered temporary and transient.

If you need to rely on an SCM checkout for your promotion process, you have to either:

  • Perform command line checkout (it will not be tracked by Jenkins), or
  • Run another job with SCM checkout (all the benefits of Jenkins tracking).

In both cases, I would assume you want to pass an SCM revision number to the promotion process (to use in command line checkout, or as parameter for calling another job). The "Trigger/Call builds" step has an option to pass parent SVN revision, but I don't know if it has the same option for Git. In worst case, on your "build" job execution, store the Git revision to a file and archive that file with the rest of the artifacts. In your promotion process, retrieve the saved file with "Copy Artifacts" step, and then extract the Git revision from that file. You can use EnvInject plugin to help with all that and make the extracted Git revision available as an Environment Variable for the promotion process.

My recommendation would be a second "Trigger/Call Builds" step in your promotion process that triggers a job dedicated to what you want, passing it a Git revision parameter.

نصائح أخرى

This has worked so far for me:

git tag MYTAG ${PROMOTED_GIT_COMMIT}
git push --tags

I am not sure if I simplify the issue, in my environment the promotion seems to be executed on master where the archived artifacts are.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top