Giter Site home page Giter Site logo

jenkinsci / multibranch-action-triggers-plugin Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 6.0 406 KB

MultiBranch Actions Trigger Plugin

Home Page: https://plugins.jenkins.io/multibranch-action-triggers/

License: MIT License

Java 98.16% HTML 1.84%
pipeline-job multibranch multibranch-pipeline trigger trigger-events pipeline declarative declarative-pipeline pipeline-trigger

multibranch-action-triggers-plugin's Introduction

MultiBranch Action Triggers Plugin

This plugin enables building/triggering other jobs when a Pipeline job is created or deleted, or when a Run (also known as Build) is deleted by a Multi Branch Pipeline Job.

Summary

Multi Branch Pipeline Jobs are capable of creating/deleting Pipelines depending on the branches in the repository. They also remove old runs, depending on the orphaned item strategy configured for the pipeline, or when a branch is deleted.

For some reasons, tasks/jobs/scripts may be needed to run depending on Pipeline creation/deletion. For example, you may need to build up a new environment when a new branch is created and this environment must be ready before the pipeline starts. Also same behavior may be necessary for destroying environments with the deletion of the branch/Pipeline.

Also, there might be reasons to start a job when a run is deleted. For example, if a run has published an artifact (e.g. a docker image) in an external storage (e.g. a docker registry), it might be desirable to remove the artifact from the external storage whenever the run is deleted.

This plugin enables triggering/building Jobs when a new Pipeline is created or deleted with in the Multi Branch Pipeline job, or when a run is deleted.

How It Works

  1. Install plugin from Update Center of Jenkins.

  2. Create your Jobs (Pipeline/FreeStyle) which will be triggered. You can define any name for your jobs.

    Example screenshot:

    1a

    1b

    1c

  3. Create your Multi Branch Pipeline

    Example screenshot:

    3a

  4. Define "Pipeline Action Triggers" Jobs at the bottom of the configuration page of the Multi Branch Pipeline.

    • This fields has Auto-Complete feature.
    • You can define more then one Job. All jobs defined in this fields will be triggered/built in the same time.
    • Do not forget to save configuration.

    Example screenshot:

    4a

    Example screenshot:

    4b

  5. (Optional) Add filtering for triggering Jobs. In default, Trigger Jobs are build for all branches which is discovered by Branch Indexing. In some cases you may need to filter branches on which Trigger Jobs will be build. To achieve this you can define both Include and Exclude Filters (wildcard).

    5a

  6. After Multi Branch Pipeline indexes the branches and creates Pipelines, you will notice that, Jobs that you defined in "Pipeline Create Event" field has the same number of builds with the number of Pipelines.

    • When you go to Configuration of the Jobs, you will notice that Build Parameter is defined automatically.
    • Branch/Pipeline name value is passed to the job by the parameter named "SOURCE_PROJECT_NAME". This parameter will have the name of the Pipeline/Branch which is created by Multi Branch Pipeline. For example if you only have master branch in your repository, this value will be "master".
    • Full name of the Branch/Pipeline is passed to the job by the parameter named "SOURCE_PROJECT_FULL_NAME". This parameter will have the full name of the Pipeline/Branch which is created by Multi Branch Pipeline. For example if you only have master branch in your repository, this value will be "MyMultiBranchPipeline/master".
    • If the Pipeline/Branch job is type of Pull Request/Merge Request, then two more parameters are passed to the job.
      • SOURCE_BRANCH_NAME is the source branch of the Pull Request/Merge Request which is created by Multi Branch Pipeline.
      • TARGET_BRANCH_NAME is the target branch of the Pull Request/Merge Request which is created by Multi Branch Pipeline.
    • You can use this variable for your needs in your scripts/pipelines.

    Example screenshots:

    6a

    6b

    6c

    6d

  7. Whenever the Multi Branch Pipeline deletes a run (either by deleting the run, or by deleting the complete branch), or whenever a run is deleted manually, the Jobs that you defined in "Run Delete Event" will be executed. Additionally, to the parameters which are passed on branch creation or deletion, two other parameters ("SOURCE_RUN_NUMBER" and "SOURCE_RUN_DISPLAY_NAME") are passed to the triggered job(s).

    Example Screenshots:

    7a

    7b

  8. (Optional) Add additional parameters for passing to Triggering Jobs. Parameters which are defined in this section will be automatically defined in Trigger Jobs and values will be passed during the build.

    Example Screenshots:

    8a

    8b

Job DSL

MultiBranch Action Triggers Plugin can be defined by using Jenkins Job DSL Plugin as shown below.

multibranchPipelineJob('multi-branch-job') {
    branchSources { // This block is for creating MultiBranch Job. Please check Job DSL Plugin for more details.
        git {
            id('123456789') // IMPORTANT: use a constant and unique identifier
            remote('https://github.com/jenkinsci/multibranch-action-triggers-plugin.git')
            credentialsId('your-credentials') 
            includes('*')
        }
    }
    properties{
        pipelineTriggerProperty{
            createActionJobsToTrigger('job1, job2') // Comma separated list of Jobs
            deleteActionJobsToTrigger('job1, job3') // Comma separated list of Jobs
            actionJobsToTriggerOnRunDelete('job2, job3') // Comma separated list of Jobs
            branchIncludeFilter('*') // Can bet set to empty string
            branchExcludeFilter('exclude') // Can bet set to empty string
            additionalParameters{ // This block is optional.
                additionalParameter{ // This block can be defined as much as required
                    name('KEY1')
                    value('VALUE1')
                }
                additionalParameter{
                    name('KEY2')
                    value('VALUE2')
                }
            }
        }
    }
}

Reporting Issues

Please create issue in this repository.

Create Issue

Thank You!

If you feel your self generous today, you can buy me a coffee : )
Or you can star the project. Thanks.

multibranch-action-triggers-plugin's People

Contributors

aytuncbeken avatar basil avatar dependabot[bot] avatar strangelookingnerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

multibranch-action-triggers-plugin's Issues

How to configure Orphaned Items Strategy so that deleting a branch triggers an action soonish?

I have a test pipeline that I'm using to test this plugin. In Orphaned Item Strategy it has Discard old items checked and both Days to keep old items and Max # of old items to keep are both empty. When I close a PR (I'm doing things off of PRs) it shows the PR name struck through, like PR-17, but my Pipeline Delete Event isn't run until I manually do something like Scan Repository Now that totally removes old items from Jenkins.

Is there a way to configure things so that my delete actions are run when the remote branch is deleted, or at least within a few hours after it is deleted?

Branch deletion on a multibranch pipeline is not triggering Pipeline Delete Event

Describe the bug
I have github webhook configured for branch deletion events and a multibranch pipeline job configured for the git repo. I have a jenkins job that just says "Hello world" and I set it under "Pipeline Delete Event" for the multibranch pipeline job. When I delete the branch, indeed the multibranch pipeline job shows the branch name crossed out. However, the "Hello world" job is not triggered. Even if I manually delete the job after the branch is deleted, the job is not triggered. I also note the same problem for "Pipeline Create Event." I set the same job trigger and it doesn't get triggered upon pipeline creation.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple Hello World pipeline.
  2. On multibranch pipeline, add that job under "Pipeline Delete Event"
  3. Ensure github webhook sends delete hooks
  4. Delete the branch, note that it gets crossed out, but the Hello world job is not trigger

Expected behavior
The job should trigger on branch deletion.

Jenkins version 2.356

When branch is deleted `Run Delete Event` runs multiple times per branch

Describe the bug
I've set up Run Delete event for cleaning up some things after the branch is absent. And also set multibranch pipeline scan trigger every 3 min. When Jenkins gets that branch is absent, Run Delete event starts job with params, but a lot of times. The first job is succeeded, but others aren't.

To Reproduce
Steps to reproduce the behavior:

  1. Create multibranch pipeline
  2. Set Run Delete event job
  3. Set scan trigger (for me it's each 3 mins)
  4. create and delete branches and see

Expected behavior
Specified job runs once.

Screenshots
image

Versions:

  • Jenkins 2.366
  • Plugin 1.8.6
  • Java 11 at controller

Bump Versions

Bumping plugin versions for fixing security vulnerabilities.

What is quitePeriod for?

Im seeing this in the job config xml:

    <org.jenkinsci.plugins.workflow.multibranch.PipelineTriggerProperty plugin="[email protected]">
      <createActionJobsToTrigger></createActionJobsToTrigger>
      <deleteActionJobsToTrigger>runthisjob</deleteActionJobsToTrigger>
      <actionJobsToTriggerOnRunDelete></actionJobsToTriggerOnRunDelete>
      <quitePeriod>0</quitePeriod>
      <branchIncludeFilter>*</branchIncludeFilter>
      <branchExcludeFilter></branchExcludeFilter>
      <additionalParameters/>
    </org.jenkinsci.plugins.workflow.multibranch.PipelineTriggerProperty>

is quitePeriod a delay timer or something?

Pipeline starts before the `RunOnPipelineCreate` finished

Describe the bug
Pipeline starts before the RunOnPipelineCreate finished

To Reproduce
Steps to reproduce the behavior:

  1. Create a Pipeline job, and use it as the RunOnPipelineCreate of a Multibranch Pipeline job
  2. Create a new branch
  3. Both the new pipeline and the PipelineCreate job run concurrently

Expected behavior
The new pipeline job should be blocked until the PipelineCreate is done

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Opera

Additional context
From the Readme, it implies the new pipeline job should be blocked until the PipelineCreate job is done.

For example, you may need to build up a new environment when a new branch is created and this environment must be ready before the pipeline starts

REQUEST FO JOINING THE JENKINS ORGANISATION

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Provide source branch name for PRs

Is your feature request related to a problem? Please describe.
I'm using this plugin to cleanup test environments. To be precise, on branch delete I'm running this command:

helmDelete(env.SOURCE_PROJECT_FULL_NAME.replaceAll('/','-').replaceAll('%2F','-'))

I'm naming test environments like $org-$repo-$branch, e.g. foo-bar-feature-baz and this plugin works great for branches that are merged directly.
However, when branches go through PR and code review process SOURCE_PROJECT_FULL_NAME looks like foo/bar/PR-123 and command above fails due to name mismatch.

Describe the solution you'd like
Having separate variable with source (and possibly target) branch name(s) would do the trick.

I want to join this oganization

I specialize in blockchain development and website creation for businesses and individuals.
I apply advanced skills to blockchain development, including expertise in smart contract creation, decentralized application (dApp) development, and blockchain architecture design. My experience includes various blockchain platforms such as Ethereum, Hyperledger, and Binance Smart Chain. I also have a deep understanding of cryptographic principles, consensus algorithms, and security best practices in blockchain technology.
I make it a priority to deliver high-quality projects while building genuine friendships and fostering meaningful relationships in both professional and personal spheres. If you are looking for someone who can support you in both business and life, send me a DM.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.