1

I have a question about How to create CODEOWNERS File using jenkins script under Workspace.

I was using this code to try to create CODEOWNERS file under Workspace directly.

fp = new FilePath(build.workspace, 'CODEOWNERS')

but it doesnt work

and the same question

Can I use

def String baseDir = "CODEOWNERS"
def dateien = findFiles(glob: baseDir)

becauese codeowners file has no type..

any solutions

user1938143
  • 1,022
  • 2
  • 22
  • 46

1 Answers1

0

A FilePath only represents a file path on a specific agent or the controller.
It does not in itself create any files.

As seen here, writing a file would be done directly in the workspace:

node {
    writeFile file: 'groovy1.txt', text: 'Working with files the Groovy way is easy.'
    sh 'ls -l groovy1.txt'
    sh 'cat groovy1.txt'
}

And findFiles should be able to look for files without "type" or extension.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi that means, I can use node to create CODEOWNERS file in the workspace? node { writeFile file: 'CODEOWNERS', text: 'Working with files the Groovy way is easy.' sh 'ls -l CODEOWNERS' sh 'CODEOWNERS' } – user1938143 Nov 22 '21 at 07:58
  • @user1938143 Yes, that is the idea. Give it a try for testing. – VonC Nov 22 '21 at 08:00
  • my gold is, I want to create a codeowners file in the workspace, and using findFiles to find all sub files, which are under sub folders, and get the contents and copy the contents to this Codeowners file – user1938143 Nov 22 '21 at 08:04
  • @user1938143 Sure. Start with the first step, and see if the codeowners is created where you want it to be. – VonC Nov 22 '21 at 08:15