Skip to content

Instantly share code, notes, and snippets.

@fty4
Last active January 12, 2021 10:57

Revisions

  1. fty4 revised this gist Jan 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion job1.Jenkinsfile
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ pipeline {
    script {
    GIT_TAG = sh (
    # will grep latest branch with versioning pattern (like v1.0, v22.44.66)
    script: 'git tag --contains HEAD | egrep "v(\d+\.?){0,3}" | head -n1',
    script: 'git tag --contains HEAD | egrep "v(\\d+\\.?){0,3}" | head -n1',
    returnStdout: true
    ).trim()
    }
  2. fty4 revised this gist Jan 12, 2021. 2 changed files with 4 additions and 3 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@
    - add each job via scm to Jenkins (named as job1 and job2 -> job1.Jenkinsfile has 'job2' defined as jobname
    - enable 'GitHub hook trigger for GITScm polling' on job1
    - set pipeline repo of job1 to match only releases (= tags/*):<br />
    Pipeline.Definition.SCM.Git.Repositories.Refspec: `'+refs/tags/*':'refs/remotes/origin/tags/*'`<br />
    Pipeline.Definition.SCM.Git.BranchesToBuild.BranchSpecifier: `**/tags/**`
    Pipeline.Definition.SCM.Git.Repositories.Refspec: `'+refs/tags/v*':'refs/remotes/origin/tags/v*'`<br />
    Pipeline.Definition.SCM.Git.BranchesToBuild.BranchSpecifier: `**/tags/v**`

    3 changes: 2 additions & 1 deletion job1.Jenkinsfile
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@ pipeline {
    steps {
    script {
    GIT_TAG = sh (
    script: 'git tag --contains HEAD',
    # will grep latest branch with versioning pattern (like v1.0, v22.44.66)
    script: 'git tag --contains HEAD | egrep "v(\d+\.?){0,3}" | head -n1',
    returnStdout: true
    ).trim()
    }
  3. fty4 revised this gist Jan 12, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # README
    - add each job via scm to Jenkins (named as job1 and job2 -> job1.Jenkinsfile has 'job2' defined as jobname
    - enable 'GitHub hook trigger for GITScm polling' on job1
    - set pipeline repo of job1 to match only releases (= tags/*):
    Pipeline.Definition.SCM.Git.Repositories.Refspec: `'+refs/tags/*':'refs/remotes/origin/tags/*'`
    - set pipeline repo of job1 to match only releases (= tags/*):<br />
    Pipeline.Definition.SCM.Git.Repositories.Refspec: `'+refs/tags/*':'refs/remotes/origin/tags/*'`<br />
    Pipeline.Definition.SCM.Git.BranchesToBuild.BranchSpecifier: `**/tags/**`

  4. fty4 created this gist Jan 12, 2021.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # README
    - add each job via scm to Jenkins (named as job1 and job2 -> job1.Jenkinsfile has 'job2' defined as jobname
    - enable 'GitHub hook trigger for GITScm polling' on job1
    - set pipeline repo of job1 to match only releases (= tags/*):
    Pipeline.Definition.SCM.Git.Repositories.Refspec: `'+refs/tags/*':'refs/remotes/origin/tags/*'`
    Pipeline.Definition.SCM.Git.BranchesToBuild.BranchSpecifier: `**/tags/**`

    21 changes: 21 additions & 0 deletions job1.Jenkinsfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    pipeline {
    agent any
    stages {
    stage('Beispiel') {
    steps {
    script {
    GIT_TAG = sh (
    script: 'git tag --contains HEAD',
    returnStdout: true
    ).trim()
    }
    }
    }
    }
    post {
    always {
    build job: 'job2',
    parameters: [[$class: 'StringParameterValue', name: 'passed_param', value: String.valueOf(GIT_TAG)]]
    }
    }
    }
    17 changes: 17 additions & 0 deletions job2.Jenkinsfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    pipeline {
    agent any
    parameters{
    string(
    name: 'passed_param',
    defaultValue: 'TESTING',
    description: 'The target environment',
    )
    }
    stages {
    stage('Example') {
    steps {
    echo params.passed_param
    }
    }
    }
    }