-
Notifications
You must be signed in to change notification settings - Fork 2
Writing Jobs
Preflight check
If you have not already created your octopusci skeleton by running octopusci-skel
, you should do so now in order for your /etc/octopusci folder to be created with some boilerplate.
The /etc/octopusci folder
Your /etc/octopusci folder has a config.yml file and a jobs folder. The config file has a 'projects' section (the other sections are out of the scope of this document). Each project object defined in this section has a few attributes such as name, owner, in addition to an oddly named attribute called "job_klass"
What is job_klass?
The job_klass attribute specified for each project in your /etc/octopusci/config.yml file is how octopusci-tentacles knows what ruby code to execute when a job appears in octopusci's queue. For our purposes lets say we have this entry in our config.yml:
# /etc/octopusci/config.yml
...
projects:
- { name: myproj, owner: keyvan, job_klass: MyprojRSpecBuildLocal, repo_uri: 'git@github.com:me/myproj', default_email: me@email.com }
...
Now when "myproj" lands in the queue, octopusci-tentacles will expect the ruby files in /etc/octopusci/jobs/ to have declared a class called MyprojRSpecBuildLocal. Important this class is supposed to subclass Octopusci::Job.
The class should be defined in some file within /etc/octopusci/jobs
So we'll create the file now to contain our new class to match the job_klass attribute. Create it at /etc/octopusci/jobs/myproj_rspec_build_local.rb
# /etc/octopusci/jobs/myproj_rspec_build_local.rb
class MyprojRSpecBuildLocal < Octopusci::Job
def self.run(job_rec)
context "RSpec Tests (commit)" do
run_shell_cmd!("STAGE=#{job_rec['stage']} pwd && source .rvmrc && bundle install && env && bundle exec motion-specwrap 2>&1", true)
end
end
end
Of course that last example is contrived and only shows a couple things in the DSL.
The Octopusci::Job DSL
-
context
- similar to RSpec's context. It can be used to separate out a certain set of tasks from others (e.g. RSpec testS vs Cucumber tests) -
run_shell_cmd!
- Use this to execute shell commands. You may optionally pass a 2nd argument oftrue
orfalse
. A true value will ensure acd
into the temporary project job directory before the command is executed.
To discover more of the DSL, explore Octopusci::Job