-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1baaefc
commit 5572335
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
pipeline { | ||
agent { | ||
docker { | ||
image 'node:14' // Use a Node.js Docker image as the build environment | ||
args '-v $HOME/.npm:/root/.npm' // Mount the npm cache to speed up builds | ||
} | ||
} | ||
|
||
stages { | ||
stage('Checkout') { | ||
steps { | ||
// Checkout code from your repository | ||
git credentialsId: 'github-credentials', url: 'https://github.com/your/repo.git' | ||
} | ||
} | ||
|
||
stage('Build') { | ||
steps { | ||
// Run build commands here (e.g., npm install, mvn clean install) | ||
sh 'npm install' // Example for Node.js project, adjust for your project's build system | ||
} | ||
} | ||
|
||
stage('Test') { | ||
steps { | ||
// Run tests here | ||
sh 'npm test' // Example for running tests with npm, adjust for your testing framework | ||
} | ||
} | ||
} | ||
|
||
post { | ||
always { | ||
// Post-build actions | ||
// Report build status to GitHub | ||
script { | ||
// Set up GitHub Checks API parameters | ||
def githubCreds = credentials('github-credentials') // Jenkins secret text credential containing GitHub personal access token | ||
def apiUrl = 'https://api.github.com' | ||
def gitHubContext = 'Jenkins CI' // Context for the GitHub status check | ||
def gitHubUrl = env.BUILD_URL // URL to Jenkins build details | ||
def gitHubCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() | ||
|
||
// Report status to GitHub | ||
withGitHubChecks( | ||
credentialsId: githubCreds, | ||
apiUrl: apiUrl, | ||
commitSha: gitHubCommit, | ||
context: gitHubContext, | ||
url: gitHubUrl, | ||
status: currentBuild.result == 'SUCCESS' ? 'success' : 'failure', | ||
description: currentBuild.result == 'SUCCESS' ? 'Tests passed' : 'Tests failed' | ||
) | ||
} | ||
} | ||
} | ||
} |