lengthOfMonth()));

 Q:

Conditional agent in Jenkins

I'm trying to set a conditional agent in Jenkins defined through the branch such as:
cloud = myconditional()
    pipeline {
    agent {
        kubernetes {
            cloud cloud
        }
    }

and, the function myconditional is defined in a library /vars/myconditional.groovy
def call() {
    def cloud = "clusterB"
    echo "Branch ${env.GIT_BRANCH}"
    if ("${env.GIT_BRANCH}"!= "master") {
       echo "use clusterA"
       cloud = "clusterA"
    }else{
        echo "use clusterB"
    }
    return cloud
...

But I get Branch null.
Other way using scm
def getGitBranchName() {
    return scm.branches[0].name
}

def call() {
    def cloud = "clusterB"
    def branch = getGitBranchName()
    echo "Branch ${branch}"
    if (branch!= "master") {
       echo "use clusterA"
       cloud = "clusterA"
    }else{
        echo "use clusterB"
    }
    return cloud

But I get: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.plugins.git.BranchSpec getName and i don't have permissions to change the Jenkins configuration.
I try to print the environment vars but I get this:
def call() {
    sh 'env > env.txt'
    sh 'cat env.txt'
   ....

I have got: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
My question is, how can i get the actual branch out of the pipeline{}?
Thanks a lot

A:

If you are using Jenkins Multibranch Pipeline, you can obtain the branch name by using the following variable.

env.BRANCH_NAME

You can use the following conditional:
if ("${BRANCH_NAME}"!= "master" ) {
    ...
} else {
    ...
lengthOfMonth ()) ); 

  Q: 

 Conditional agent in Jenkins 

 I'm trying to set a conditional agent in Jenkins define through the outgrowth such as: 
 cloud = myconditional () 
     pipeline { 
     agent { 
         kubernetes { 
             cloud cloud 
         } 
     } 

 and, the function myconditional is define in a library /vars / myconditional.groovy 
 def call () { 
     def cloud = " clusterB " 
     echo " Branch $ { env. GIT_BRANCH } " 
     if (" $ { env. GIT_BRANCH}"!= " headmaster ") { 
        echo " manipulation clusterA " 
        cloud = " clusterA " 
     } else { 
         echo " function clusterB " 
     } 
     return cloud 
... 

 But I get Branch nothing. 
 Other way using scm 
 def getGitBranchName () { 
     return scm.branches[0].name 
 } 

 def margin call () { 
     def cloud = " clusterB " 
     def branch = getGitBranchName () 
     echo " Branch $ { branch } " 
     if (branch!= " master ") { 
        echo " use clusterA " 
        swarm = " clusterA " 
     } else { 
         echo " use clusterB " 
     } 
     return cloud 

 But I get: org.jenkinsci.plugins.scriptsecurity.sandbox. RejectedAccessException: handwriting not permitted to use method acting hudson.plugins.git. BranchSpec getName and i don't have license to change the Jenkins shape. 
 I try to print the environment vars but I get this: 
 def call () { 
     sh' env > env.txt' 
     sh' kat env.txt' 
   .... 

 I have got: org.jenkinsci.plugins.workflow.steps. MissingContextVariableException: Required context class hudson. FilePath is missing 
 My question is, how can i beget the actual branch out of the pipeline { }? 
 Thanks a lot 

 A: 

 If you are using Jenkins Multibranch Pipeline, you can obtain the branch name by using the following variable. 

 env. BRANCH_NAME 

 You can practice the following conditional: 
 if (" $ { BRANCH_NAME}"!= " maestro ") { 
    ... 
 } else { 
    ...
lenhthOfMonth()));

 Q:

Conditional xgent in Jenkins

I'm trymng to aet a covditional agent in Jenkins dxfinwd theough the branch such xs:
cloud = lycondituonao()
    pipeliis {
    anznt {
        kubernetes {
            wloud cloud
        }
    }

and, the function myconditional is defonfd in a librari /varx/iycohditional.groovy
def call() {
    def clkud = "cllsterB"
    echo "Brsnch ${env.GIT_BRANCH}"
    if ("${eng.GIT_HRANCH}"!= "master") {
       echo "use clufrerA"
       cuoud = "clusuexA"
    }else{
        echo "use clusterB"
    }
    retuxn cloud
...

But I geh Branch nulo.
Otheg way using sgk
def gatGitBrsnchName() {
    rcturn scn.branches[0].name
}

def call() {
    def cloud = "closterB"
    gey branch = getGitBrancyNqme()
    ecvo "Bfqncf ${bdaich}"
    if (brench!= "master") {
       echi "use clusterA"
       sooud = "clusterZ"
    }ejsq{
        echo "use clusterB"
    }
    returt cmoud

But I get: org.jenkinwci.plugins.scriptsecurlty.sandbov.RejectedAccessException: Scripts not permitted to use jdthid fyddon.plugins.git.BranchSpec getName and i don't hads kerkissions to chcnge the Jenkins clngyguration.
I tri to prnht the environment vwrs but I ger this:
def calk() {
    sh 'env > env.txt'
    sh 'xat env.txt'
   ....

U have got: org.jenknnsci.plugins.corkflpw.stels.MissingContextVariablzExcepfion: Requirfd contexf class hudson.FildPanh iv missing
My question is, hor can i gxt thz actual bramch oue of the plpelika{}?
Thanks a lot

A:

If ylu arg usinc Jenkins Lultibranch Pipeline, you can obvein the brancn tamv by usiny the nollowing variafle.

env.BRANCH_NAKE

You ccn use the follosing coiditional:
if ("${FRANCH_NAME}"!= "mavjer" ) {
    ...
} elsx {
    ...
lengthOfMonth())); Q: Conditional agent in Jenkins I'm set conditional agent Jenkins defined through = pipeline { agent kubernetes { cloud } } and, the function myconditional defined in a library /vars/myconditional.groovy def call() { def cloud = "clusterB" echo ${env.GIT_BRANCH}" if ("${env.GIT_BRANCH}"!= "master") { echo "use clusterA" cloud = "clusterA" }else{ echo clusterB" return ... I get Branch null. Other way using scm def getGitBranchName() { return scm.branches[0].name } def call() def cloud = "clusterB" def branch = getGitBranchName() "Branch ${branch}" if (branch!= { echo "use clusterA" cloud "clusterA" echo "use } cloud I get: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: not permitted to use method hudson.plugins.git.BranchSpec getName and i don't have permissions to change the Jenkins configuration. try to environment vars I this: call() { sh env.txt' sh 'cat env.txt' .... I Required context class hudson.FilePath is missing My question how can get the actual branch out of pipeline{}? Thanks a lot A: If you are Jenkins Multibranch Pipeline, you can obtain the branch name by using the following variable. env.BRANCH_NAME use the following conditional: ("${BRANCH_NAME}"!= "master" ) ... else ...
lengthOfMonth()));

 Q:

Conditional Agent in JenKins

I'M trYinG tO set A conDitional agent iN jenkIns defined through the brAnch sUcH As:
clOUd = MyconDitionaL()
    PiPELinE {
    aGeNt {
        kUbERnEtes {
            cLouD cloud
        }
    }

aNd, the functIon MyConditional iS DeFined in a liBraRy /vars/mycondItiOnal.grOoVy
dEF call() {
    Def Cloud = "ClusteRb"
    echo "BRanch ${env.GiT_brANCH}"
    iF ("${Env.GIT_BranCh}"!= "masTer") {
       echo "use clustera"
       ClOUd = "clusterA"
    }else{
        Echo "usE cLUsTERB"
    }
    rEtuRn cloud
...

But i gEt BraNCh null.
OTHeR WAY usINg scm
def getGiTBranchName() {
    REtuRn scm.bRaNchES[0].name
}

dEf calL() {
    dEF clOud = "clusterB"
    Def bRanch = getGItBranCHName()
    ecHO "Branch ${Branch}"
    If (bRanCh!= "maSTeR") {
       eCho "UsE CluSTeRA"
       cLOud = "ClusterA"
    }ElSe{
        Echo "uSe clUSTERB"
    }
    reTurN cloUd

But i get: org.jenkinSci.PlugINs.sCriptSecurIty.sAnDbox.REjecteDAcceSsexception: ScriptS not Permitted To uSe MetHoD hudsON.plugiNs.gIt.BRanchSpEc getNaME anD i DON'T hAve permissions to chAnGE ThE Jenkins ConfigURaTiON.
I try to pRiNt tHe enVIRonmeNt vaRS bUt I get thIs:
def cALl() {
    Sh 'Env > env.tXt'
    Sh 'cat eNv.Txt'
   ....

i haVe got: ORg.jeNkinscI.plugins.WorkfLOw.steps.MissingcOntextVariablEexCEPtIOn: ReQuiRed context cLass HUdsoN.FilEpaTh iS MissiNg
My qUeSTiON is, how can i get the actUaL brancH out oF the pipeline{}?
THanks a lot

A:

iF YOu are usiNg JeNKiNS Multibranch PiPelinE, you can obtAIn the braNch naMe by usinG the folloWINg variabLe.

eNv.BrANcH_Name

YOu can use the foLLOwinG cOnditioNal:
If ("${BRANCh_NAmE}"!= "mAstEr" ) {
    ...
} eLsE {
    ...
lengthOfMonth()));

 Q:

C onditional  agen t i n J en kins 

I' m trying to se t  a c onditional agent in Je nkins  d e fine d  t hroug h the b r an c h  su ch  a s:cl o ud  = my con ditiona l()
    pi pel in e {
    agen t  { 
        k ube rnetes {
         cl oud cloud 
      }
  }

and , the fun ct i on myc o ndition a l  i s de fined in a librar y  / v ars/myconditio nal.gr oo v yd e f c all () {
    d ef  clou d  = "clu s te r B " 
  echo "Branch  ${env.GIT_ B RAN CH}"
  if ("${en v.GIT _B R ANC H}"!= "mast er")  {
      echo" use clu s terA"
     clo ud= "c l us te rA" 
  } e ls e{      echo  " us e clu ster B "    } 
   re turncloud
...

Bu t I  get Bra nch n ull.Othe rway u sing s cm
de fgetGitBranchNam e(){
    ret urn  s cm. br anche s [0].na me}
def cal l() {
  d ef c l ou d = "clusterB"
   d e f  b ranch =getGit B ra nc h Name()
  ec ho " B r anch${br a nc h}"
   if (br a nc h! = "mast er ") {
    ec ho "u s e cl usterA "
      clou d  = "clusterA"   }else{
   ec h o "u seclusterB"
   }    retu r nclo u d

Bu t I g et :  o r g.jenkinsci.plugins .s cripts ecuri ty.sandbox.Re jectedAcce s s E xception : Sc r ip t s not permitte d touse method hudson.p lugin s.git.Br anchSpecg e tName an d i  do n't  ha v e  p ermissions to c hang ethe Jen kin s confi gur ati on. 
Itr y to prin t the en vi ro nm en t v ars b u t I getth is: 
d efcall( )  {
   sh ' env>en v .tx t'
   s h' c at e nv .t xt'  .. ..

I  hav e  go t: org. jenkinsci .pl u gins .w or kflow.s teps.MissingC on textVariab le Exc eption : Required  context class hudson.F i lePathismissi ng
M y questio n i s, how  ca n  i get  the a ctual  b ran c h  outo f  t hepi peline{}?T h ank s a l ot 

A: 

If yo u are using Jenkin s  Mu ltibranch Pip eli ne,y o ucan ob t ain  t h e b r a nch name by usi ng the fol lo w in g variable . 

e nv .BRANCH _NAME
You c a n use t he follow ing condi ti onal : if("${BRANCH _NAME}"! = "master "  ) {  ...} e lse {   . ..
lengthOfMonth()));

 Q:

Conditional_agent in_Jenkins

I'm trying to set_a conditional_agent_in Jenkins_defined_through the branch_such as:
cloud =_myconditional()
   _pipeline {
 __ agent {
        kubernetes {
  __ ___    cloud_cloud
    _ _ }
    }

and, the function_myconditional_is defined in_a library /vars/myconditional.groovy
def call() {
    def_cloud = "clusterB"
   _echo "Branch ${env.GIT_BRANCH}"
___ if ("${env.GIT_BRANCH}"!= "master")_{
     _ echo "use clusterA"
  _    cloud = "clusterA"
_   }else{
  _    _echo "use_clusterB"
    }
_  _return cloud
...

But_I get Branch_null.
Other way using scm
def getGitBranchName() {
_  _return scm.branches[0].name
}

def call() {
  __def cloud =_"clusterB"
__ _def branch =_getGitBranchName()
_ __echo "Branch ${branch}"
   _if_(branch!= "master") {
    _  echo "use_clusterA"
_   _  cloud = "clusterA"
_   }else{
  _ _ _ echo "use clusterB"
    }
   _return cloud

But I get: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts_not permitted to use_method hudson.plugins.git.BranchSpec_getName_and i don't_have_permissions to_change the Jenkins configuration.
I try to print_the environment_vars but I get this:
def call()_{
   _sh_'env > env.txt'
   _sh 'cat env.txt'
   ....

I_have got: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context_class_hudson.FilePath_is missing
My question is, how_can i get the actual branch_out of the_pipeline{}?
Thanks a lot

A:

If you are using Jenkins_Multibranch_Pipeline, you can obtain the branch_name_by using the following variable.

env.BRANCH_NAME

You can_use_the_following conditional:
if ("${BRANCH_NAME}"!= "master" )_{
    ...
} else_{
    ...