Langdon
Langdon

Reputation: 20053

Continuous Delivery with VSTS and Jenkins

I'm trying to get continuous delivery going with Jenkins (building, deploying) and VSTS (source control). This is the desired workflow:

  1. a developer branches off master, makes changes, creates a pull request
  2. another developer reviews the PR and eventually merges it into master
  3. some system (Jenkins or VSTS) detects that a PR was merged into master and...
    1. increments a version number stored in a file within the repo
    2. commits the version change back to master
    3. builds
    4. deploys

I was using Service Hooks within VSTS to detect the merge to master and execute a Jenkins task. VSTS has 3 hooks I can use:

  1. Build completed
  2. Code pushed
  3. Pull request merge commit created

I was under the impression that the third option would only occur when a PR was merged, but that's not the case. Any additional commits to the branch, while it's associated with the PR triggers the hook. This causes a bunch of unnecessary deployments.

I figured I could make Jenkins detect changes within VSTS. There's a "Poll SCM" option, which takes a cron-like schedule. The utterly confusing thing is, it doesn't appear that I can configure what exactly will be polled every X minutes (which repo, which branch).

What are my options here to trigger Jenkins tasks only when a PR is merged to master? I would use the VSTS "Code pushed" Service Hook, but it goes into an infinite loop because Jenkins pushes to master when it increments the version.

enter image description here

Upvotes: 0

Views: 461

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

Refer to these steps below:

  1. Create a new build definition for master
  2. Select Triggers and enable Continuous Integration
  3. Set the Branch Filters and Path filters (exclude the version number file that need to be changed)
  4. Add task to modify version number file (e.g. PowerShell)
  5. Add Command Line task (Tool: git; Arguments: config --global user.email “[email protected]”; Working folder: $(build.sourcesdirectory))
  6. Add Command Line task (Tool: git; Arguments: config --global user.name "Your Name"; Working folder: $(build.sourcesdirectory))
  7. Add Command Line task (Tool: git; Arguments: add [the modified file]; Working folder: $(build.sourcesdirectory))
  8. Add Command Line task (Tool: git; Arguments: commit -m “update version”; Working folder: $(build.sourcesdirectory))
  9. Add Command Line task (Tool:git; Arguments: push origin HEAD:$(Build.SourceBranchName) ”; Working folder: $(build.sourcesdirectory))
  10. Add Jenkins Queue Job task to trigger Jenkins job

Upvotes: 1

Related Questions