-1

I can do this manually in the console with a job dsl step, but can't figure out how to accomplish from a pipeline - declarative or scripted.

J Vipe
  • 39
  • 1
  • 5

2 Answers2

0

If you want to create a directory, then you can use mkdir.

pipeline {
agent any 
stages 
    {
     stage ("stage 1"){
          steps
            {
               script {
                 bat returnStatus: true, script:"mkdir Myfolder"
                 //   OR
                 sh "mkdir -p myfolder"
                 }
             }
         }
     }
}
Altaf
  • 2,838
  • 1
  • 16
  • 8
  • sorry didn't get back on this. No, this was not what I was looking for. Was looking for way to create a Jenkins folder. I ended up writing a /vars script using com.cloudbees.hudson.plugins.folder.* along with jenkins.model.Jenkins - which worked – J Vipe Jun 24 '21 at 21:24
0

'folder' is like 'job' and can take description and displayName if you choose

folder('myFolder'){
    description('my description')
    displayName('My Display Name')
}

If the question is, How can i add a folder using a Jenkins pipeline script (Jenkinsfile)? You will likely want to look at your 'Snippet Generator' http://<your-jenkins-instance:8080>/pipeline-syntax/ and look at the 'jobDsl' Sample Step. Generated code from the Snippet Generator will look like this.

jobDsl scriptText: '''folder(\'myFolder\'){
    description(\'my description\')
    displayName(\'My Display Name\')
}'''

And your Pipeline script would look like

pipeline {
    agent any

    stages {
        stage('Add Folder') {
            steps {
                jobDsl scriptText: """folder('myFolder'){
    description('my description')
    displayName('My Display Name')
}"""
            }
        }
    }
}
Wayne
  • 1
  • 3