Skip to content

Commit

Permalink
Add automatic triggers to jenkins workflow (#188)
Browse files Browse the repository at this point in the history
* Add triggers

Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Jul 29, 2022
1 parent 58c053c commit a1c6085
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
13 changes: 13 additions & 0 deletions jenkins/publish-snapshot.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ pipeline {
alwaysPull true
}
}
triggers {
GenericTrigger(
genericVariables: [
[key: 'ref', value: '$.ref'],
],
tokenCredentialId: 'jenkins-opensearch-java-generic-webhook-token',
causeString: 'A commit was pushed on opensearch-project/opensearch-java repository main branch causing this workflow to run',
printContributedVariables: false,
printPostContent: false,
regexpFilterText: '$ref',
regexpFilterExpression: '^(refs/heads/main)$'
)
}
stages {
stage('Publish to Sonatype Snapshots Repo') {
steps {
Expand Down
45 changes: 19 additions & 26 deletions jenkins/stage-maven-release.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,31 @@ pipeline {
alwaysPull true
}
}
triggers {
GenericTrigger(
genericVariables: [
[key: 'ref', value: '$.ref'],
[key: 'VERSION', value: '$.ref', regexpFilter: 'refs/tags/v' ],
],
tokenCredentialId: 'jenkins-opensearch-java-generic-webhook-token',
causeString: 'A tag was cut on opensearch-project/opensearch-java repository causing this workflow to run',
printContributedVariables: false,
printPostContent: false,
regexpFilterText: '$ref',
regexpFilterExpression: '^refs/tags/.*'
)
}
environment {
VERSION = "${params.VERSION}"
ARTIFACT_PATH = "$WORKSPACE/build/repository/org/opensearch/client/opensearch-java/${VERSION}"
ARTIFACT_PATH = "$WORKSPACE/build/repository/org/opensearch/client/opensearch-java/$VERSION"
}
stages {
stage('parameters') {
steps {
script {
properties([
parameters([
string(
name: 'REF',
trim: true
),
string(
name: 'VERSION',
trim: true
)
])
])
if (params.REF.isEmpty() || params.VERSION.isEmpty()) {
currentBuild.result = 'ABORTED'
error('Missing REF and/or VERSION.')
}
}
}
}
stage('Publish to Maven Local') {
steps {
// checkout the commit
git url: 'https://github.com/opensearch-project/opensearch-java.git', branch: 'main'
sh('git checkout ${REF}')
checkout([
$class: 'GitSCM', userRemoteConfigs: [[url: 'https://github.com/opensearch-project/opensearch-java.git']],
branches: [[name: "$ref"]]
])

// publish maven artifacts
sh('./gradlew --no-daemon publishPublishMavenPublicationToLocalRepoRepository')
Expand Down

0 comments on commit a1c6085

Please sign in to comment.