开发者

Using un-managed file in Jenkins build step

开发者 https://www.devze.com 2023-04-06 05:16 出处:网络
I\'ve just started using Jenkins today, so it\'s entirely possible that I\'ve missed something in the docs.

I've just started using Jenkins today, so it's entirely possible that I've missed something in the docs.

I currently have Jenkins set up to run unit tests from a local Git repo (via plugin). I have set up the environment correctly (at least, in a seemingly working condition), but have run into a small snag.

I have a single settings.py file that I have excluded from my git repo (it contains a few keys that I'm using in my app). I don't want to include that file into my git repo as I'm p开发者_如何学Clanning on OS'ing the project when I'm done (anyone using the project would need their own keys). I realize that this may not be the best way of doing this, but it's what's done (and it's a small personal project), so I'm not concerned about it.

The problem is that because it's not under git management, Jenkins doesn't pick it up.

I'd like to be able to copy this single file from my source directory to the Jenkins build directory prior to running tests.

Is there a way to do this? I've tried using the copy to slave plugin, but it seems like any file that I want would first (manually) need to be copied or created in workspace/userContent. Am I missing something?


I would suggest using some environment variable, like MYPROJECT_SETTINGS. So when running the task by Jenkins you can overwrite the default path to whatever you can put your settings file for Jenkins in.

The other option, in case you don't want to copy settings file to each build-machine by hand, would be making a settings.py with some default fake keys, which you can add to your repo, and a local settings file with real keys, which overwrites some options, e.g.:

# settings.py file
SECRET_KEY = 'fake stuff'

try:
    from settings_local import *
except ImportError:
    pass


I am using the Copy Data To Workspace Plugin for this, Copy to Slave plugin should also work, but I found Copy Data To Workspace Plugin to be easier to work with for this use-case.


Why just not use "echo my-secret-keys > settings.txt" in jenkins and adjust your script to read this file so you can add it to report?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号