Reading file from Workspace in Jenkins with Groovy script

前端 未结 7 1565
广开言路
广开言路 2020-11-30 04:12

I want to add a Build step with the Groovy plugin to read a file and trigger a build fail depending on the content of the file.

How can I inject the workspace file p

7条回答
  •  生来不讨喜
    2020-11-30 04:26

    I realize this question was about creating a plugin, but since the new Jenkins 2 Pipeline builds use Groovy, I found myself here while trying to figure out how to read a file from a workspace in a Pipeline build. So maybe I can help someone like me out in the future.

    Turns out it's very easy, there is a readfile step, and I should have rtfm:

    env.WORKSPACE = pwd()
    def version = readFile "${env.WORKSPACE}/version.txt"
    

提交回复
热议问题