# Prioritize the build queue in Declarative Jenkins Pipeline

**URL:** https://community.jenkins.io/t/prioritize-the-build-queue-in-declarative-jenkins-pipeline/4514
**Category:** Using Jenkins
**Tags:** question
**Created:** [November 10, 2022, 8:41am UTC](https://community.jenkins.io/t/prioritize-the-build-queue-in-declarative-jenkins-pipeline/4514 "2022-11-10T08:41:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![CJAY](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@CJAY](https://community.jenkins.io/u/CJAY)
#### Post date: [November 10, 2022, 8:41am UTC](https://community.jenkins.io/t/prioritize-the-build-queue-in-declarative-jenkins-pipeline/4514/1 "2022-11-10T08:41:35Z")

</div>

**What I want:**

I want to change/sort the build queue in my Jenkins file (declarative Pipeline). Actually I want to make priority in my builds.

I am familiar with the following plugins:

- [PrioritySorter](https://plugins.jenkins.io/PrioritySorter/)

- [accelerated-build-now-plugin](https://plugins.jenkins.io/accelerated-build-now-plugin/)

**Description of my problem:**

My Pipeline runs on more executors (more labels). The `TRIGGERS` label is not limited so many builds can run on it (Eg.: 100). The `MAIN` label is limited, only some builds can run on it (Eg.: 10). So If I have 30 builds on the `TRIGGERS` label then 20 build will be in the queue (waiting for free executor). I have a condition and if this condition is `True`, the build should be handled as Prio1. It means an “Important” build should be the first in the queue. So I want to prioritize the builds for `MAIN` label (Change the default `FIFO` way).

**Example code:**

```auto
pipeline {
    agent { label 'TRIGGERS' } // Many builds are possible (Eg.: 100).
    stages{
        stage('Pre-preparation'){
            script {
                echo "Running Pre-preparation on '${env.NODE_NAME}' node." // Run on TRIGGER
                if(env.IMPORTANT){
                    echo "This build should be the PRIO 1 (Not waiting previous build in queue)!"
                }
            }
        }
        stage('Build activities on MAIN'){
            // If there isn't free executor the builds are waiting here for free executor.
            // One-by-one, FIFO way. I want to change that mechanism!
            agent { label "MAIN" } // Some builds are possible (Eg.: 10).
            stages{
                stage('Preparation 1'){
                    steps {
                        script {
                            echo "Running preparation 1 on '${env.NODE_NAME}' node." // Run on MAIN
                        }
                    }
                }
                stage('Preparation 2'){
                    steps {
                        script {
                            echo "Running preparation 2 on '${env.NODE_NAME}' node." // Run on MAIN
                        }
                    }
                }
            }
        }
    }
}

```

**My questions:**

- How can I change the order of the build queue (change the default `FIFO` way)?
- How can I prioritize my builds for the `MAIN` label?

**NOTE:**

- Only declarative Pipeline compatible solution is possible!
