问题
Hello stackoverflow/circleci gods.
I have been using circleCI for a while now and I have a question about the 'checkout' step which I will do my best to explain. This is a snippet from my circleCI config file (I have a job 'a-job' whose first step is checkout):
a-job:
docker:
- image: docker-image-here
steps:
- checkout
...
My question is, does the circleci step 'checkout' pull the latest code from master or the code for the specific commit.
i.e. does checkout simply git clone master:latest or does it git clone SPECIFIC COMMIT HERE
回答1:
disclaimer: Developer Evangelist at CircleCI
VonC's answer is incorrect. In CircleCI 2.0 (which is what that config is), the "special step" checkout
checks out the current commit. The current commit is the commit that initiated the CI run in the first place.
So whenever you git push
to GitHub or Bitbucket, that commit gets built and that's the commit that the checkout
step retrieves. In the case where you git push
multiple commits at the same time, the most recent commit is the one a build will be started for.
回答2:
By default, the CircleCI checkout step will checkout the default branch of your remote repo (so usually master)
Actually: the commit pushed (see FelicianoTech's answer).
But you can see here that your yaml file can specify filter branches.
That way, you build only pushed commits which are part of specific branches:
workflows:
version: 2
dev_stage_pre-prod:
jobs:
- test_dev:
filters:
branches:
only:
- dev
- /user-.*/
- test_stage:
filters:
branches:
only: stage
- test_pre-prod:
filters:
branches:
only: /pre-prod(?:-.+)?$/
As mentioned here:
The checkout step is a convenient wrapper for a bash script that checks out your code. You can see the actual checkout code by expanding the Checkout code section of your job page on a previous job run.
If you'd like to modify the checkout step, you can copy/paste this code from the job page directly into your config.yml or into a bash script using a run step.
From here you can modify the checkout process to suit your needs. Remember to remove the convenience checkout step after adding your own custom run step checkout.
来源:https://stackoverflow.com/questions/50093304/does-circleci-checkout-pull-the-latest-code-from-master-or-the-code-for-the-spec