1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2024-10-27 20:34:20 +00:00

add support for global, node and job level env files

This commit is contained in:
Oliver Giles 2015-09-19 14:55:16 +02:00
parent 1484f7a706
commit 291428ef2d
3 changed files with 25 additions and 3 deletions

View File

@ -460,6 +460,14 @@ void Laminar::assignNewJobs() {
if(fs::exists(cfgDir/"after")) if(fs::exists(cfgDir/"after"))
run->addScript((cfgDir/"after").string()); run->addScript((cfgDir/"after").string());
// add environment files
if(fs::exists(cfgDir/"env"))
run->addEnv((cfgDir/"env").string());
if(fs::exists(cfgDir/"nodes"/node.name/"env"))
run->addEnv((cfgDir/"nodes"/node.name/"env").string());
if(fs::exists(cfgDir/"jobs"/run->name/"env"))
run->addEnv((cfgDir/"jobs"/run->name/"env").string());
KJ_LOG(INFO, "Queued job to node", run->name, run->build, node.name); KJ_LOG(INFO, "Queued job to node", run->name, run->build, node.name);
// notify clients // notify clients

View File

@ -17,7 +17,7 @@
/// along with Laminar. If not, see <http://www.gnu.org/licenses/> /// along with Laminar. If not, see <http://www.gnu.org/licenses/>
/// ///
#include "run.h" #include "run.h"
#include "conf.h"
#include <iostream> #include <iostream>
#include <kj/debug.h> #include <kj/debug.h>
@ -26,7 +26,6 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
std::string to_string(const RunState& rs) { std::string to_string(const RunState& rs) {
switch(rs) { switch(rs) {
case RunState::PENDING: return "pending"; case RunState::PENDING: return "pending";
@ -47,8 +46,8 @@ Run::Run() {
Run::~Run() { Run::~Run() {
KJ_DBG("Run destroyed"); KJ_DBG("Run destroyed");
//delete log;
} }
std::string Run::reason() const { std::string Run::reason() const {
if(!parentName.empty()) { if(!parentName.empty()) {
return std::string("Triggered by upstream ") + parentName + " #" + std::to_string(parentBuild); return std::string("Triggered by upstream ") + parentName + " #" + std::to_string(parentBuild);
@ -81,6 +80,13 @@ bool Run::step() {
chdir(wd.c_str()); chdir(wd.c_str());
for(std::string file : env) {
StringMap vars = parseConfFile(file.c_str());
for(auto& it : vars) {
setenv(it.first.c_str(), it.second.c_str(), true);
}
}
setenv("PATH", PATH.c_str(), true); setenv("PATH", PATH.c_str(), true);
setenv("lBuildNum", buildNum.c_str(), true); setenv("lBuildNum", buildNum.c_str(), true);
setenv("lJobName", name.c_str(), true); setenv("lJobName", name.c_str(), true);
@ -110,6 +116,9 @@ bool Run::step() {
void Run::addScript(std::string script) { void Run::addScript(std::string script) {
scripts.push(script); scripts.push(script);
} }
void Run::addEnv(std::string path) {
env.push_back(path);
}
void Run::reaped(int status) { void Run::reaped(int status) {
procStatus = status; procStatus = status;
} }

View File

@ -21,6 +21,7 @@
#include <string> #include <string>
#include <queue> #include <queue>
#include <list>
#include <functional> #include <functional>
#include <ostream> #include <ostream>
#include <unordered_map> #include <unordered_map>
@ -57,6 +58,9 @@ public:
// adds a script to the queue of scripts to be executed by this run // adds a script to the queue of scripts to be executed by this run
void addScript(std::string script); void addScript(std::string script);
// adds an environment file that will be sourced before this run
void addEnv(std::string path);
// called when a process owned by this run has been reaped. The status // called when a process owned by this run has been reaped. The status
// may be used to set the run's job status // may be used to set the run's job status
void reaped(int status); void reaped(int status);
@ -85,6 +89,7 @@ public:
private: private:
std::queue<std::string> scripts; std::queue<std::string> scripts;
std::string currentScript; std::string currentScript;
std::list<std::string> env;
}; };