Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve jenkins/next docs #1794

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions docs/pages/docs/build-platforms/jenkins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ title: Jenkins 2
The following config declares the `release` action that run on all branches. The job will either release:

- a new `latest` version from `baseBranch`
- a `canary` build from a pull request (only on the main fork and if your package manager plugin implements them)
- a `canary` build from a pull request (only if your package manager plugin supports it)

**`Jenkinsfile`**

> :warning:You must use some sort of step that implements `skip ci` functionality. Otherwise you will get stuck in a release loop!
> :warning: You must use some sort of step that implements `skip ci` functionality.
> Otherwise you will get stuck in a release loop!

```groovy

pipeline {
environment {
NPM_TOKEN = credentials('NPM_TOKEN')
Expand Down Expand Up @@ -56,23 +56,11 @@ pipeline {
stage('Publish') {
parallel {
stage('Canary') {
when {
allOf {
changeRequest();
expression { env.CHANGE_BRANCH != 'next' }
}
}
when { changeRequest(); }
steps {
sh "auto shipit"
}
}
stage('Next') {
when { branch 'next' }
steps {
sh 'git checkout -b next'
sh "auto shipit"
}
}
stage('Latest') {
when { branch 'main' }
steps {
Expand All @@ -96,6 +84,56 @@ pipeline {
}
```

## Configuring Prereleases

For `auto`'s prerelease to work you need to makes sure that you jenkins instance is configured correctly.

1. Go to `General > Projects > GitHub Organization` and add a `Behaviors` that enables branch builds.

![A screenshot of the jenkins configuration](/jenkins-next-branches.png)

2. Add this to the top of your `Jenkinsfile`.

```groovy
// Exit the branch build if not on "baseBranch" or a prerelease, but still do PR builds
if (env.BRANCH_NAME != "master" && env.BRANCH_NAME != "next" && !env.BRANCH_NAME.startsWith('PR-')) {
echo ("Aborting build. Only the master/next branch and PR builds run.")
currentBuild.result = 'SUCCESS'
return
}
```

If your successful you will see two separate builds in your PRs: `pr-merge` and `branch`.

3. Modify your `canary` stage to not build the prerelease branch

```groovy
stage('Canary') {
when {
allOf {
changeRequest();
expression { env.CHANGE_BRANCH != 'next' }
}
}
steps {
sh "auto shipit"
}
}
```
4. Add a stage for the prerelease

```groovy
stage('Next') {
when { branch 'next' }
steps {
sh 'git checkout -b next'
sh "auto shipit"
}
}
```

5. Open a PR from your prerelease branch into your baseBranch and enjoy your prerelease! :tada:

## Troubleshooting

If you are having problems make sure you have done the following:
Expand Down
Binary file added docs/public/jenkins-next-branches.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,13 @@ export const commands: AutoCommand[] = [
name: "next",
group: "Release Commands",
description: endent`
Make a release for your "prerelease" release line. This is ran automatically from "shipit".
Make a release for your "prerelease" release line. This is ran automatically by "shipit" in a prerelease branch.

1. Creates a prerelease on package management platform
2. Creates a "Pre Release" on GitHub releases page.
2. Creates a "Pre Release" on GitHub releases page
3. If ran from a PR build in a CI, posts the prerelease's full releases notes and expected version of the prerelease

Calling the \`next\` command from a prerelease branch will publish a prerelease, otherwise it will publish to the default prerelease branch.
Calling the \`next\` command from a prerelease branch will publish a prerelease for just that branch, otherwise it will publish to the default prerelease branch.
`,
examples: ["{green $} auto next"],
options: [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ export default class Auto {
}

if (!options.dryRun) {
await this.checkClean()
await this.checkClean();
}

await this.setGitUser();
Expand Down