How to run a rake task depending on environment? - ruby

I'm trying to export Mixpanel raw data, as documented here
https://mixpanel.com/docs/api-documentation/exporting-raw-data-you-inserted-into-mixpanel
As the Mixpanel team didn't bother to just provide a script doing this, a kind soul made this Rake task
https://gist.github.com/wongpeiyi/3217208
I figured out that it needs to go into a file named "Rakefile", and executed with
$ rake mixpanel:pull
However, that gives
rake aborted!
Don't know how to build task 'environment'
Tasks: TOP => mixpanel:pull
How can this task be run?
Thanks!

The rake task was problably written to be included in a rails project. You can just remove the dependency on the :environment task.
So change the task line to
task :pull do
that should do the trick. It could be possible that some gems are missing (that is what the :environment task does: it loads the rails environment).

Related

MyTask getting unwantedly executed when building

I want to print a link to our team's documentation if the developer types:
gradle help
using this task:
task help {
println "Full Documentation"
println "https://confluence.org.com/Help"
}
which it does.
However, I do not want it to execute when I run:
gradle build
Is the help task supposed to run whenever build is run? If not, why does this task get executed? As you can tell, my understanding of gradle is limited.
You are effectively overriding the built-in help task that Gradle provides. As a result, other tasks or plugins in your project may be referencing that task already or other parts in the overall Gradle build rely or use help in some fashion.
To summarize, do not override Gradle built-in tasks otherwise it will lead to unexpected/unintended consequences.
To fix, rename your task to something other than help.

Calling Gradle commands and tasks with parameters from Gradle Task

I have a current setup in my build.gradle that I'm trying to understand. I need a number of tasks to go off in a very specific order and execute all with one task call. The setup I want looks like this:
1.) Run liquibase changeset into predefined database
2.) Run a number of tests against database
3.) Rollback all changes made with the previous changeset
I want the database in a 'clean' state every time I test it. It should have only the changes I expect and nothing else. The liquibase is set up with the Gradle plugin for it and the changeset is applied/updated. However, I don't want to call the command manually. This will be something that needs to run in continuous integration, so I need to script it so I simply have our CI call one task and it then runs each task, in order, until the end. I'm unsure of how to call the Gradle command-line task from inside of itself (ie inside the build.gradle file) and then also pass parameters to it (since I'll need to call some type of rollback command task to get the database to be what it was before calling the update).
Right now, all I'm doing is calling the command line tasks like this:
$ gradle update
$ gradle test
$ gradle rollbackToDate -PliquibaseCommandValue=2016-05-25
Again, I can't call them by the command line alone. I need a custom task inside Gradle so that I could just call something like:
$ gradle runDatabaseTests
...And I would have it do everything I expect.
There is no gradle way to invoke/call a task from another task directly. What you can do instead is to use dependsOn or finalizedBy to setup task dependencies which will force the prereq tasks to run first.
If you declare a task:
task runDatabaseTests(dependsOn: [update, test, rollbackToDate]) << {
println "I depend on update, test and rollbackToDate"
}
when you call
gradle runDatabaseTests -PliquibaseCommandValue=2016-05-25
it will force update, test and rollbackToDate first. You can control the order in which they're run, if you care about that, by using mustRunAfter and/or shouldRunAfter

In gradle, how can I run a task against all projects recursively from command line?

I'm looking for a syntax along the lines of ./gradlew :all:myTask that I can quickly execute from the command line. I must have missed it in the documentation somewhere.
I know I can modify the build to include a new task that runs a task against all sub-projects, however I'd prefer to not mess with modifying the build for simple one-off scenarios.
If I understand your goal correctly, running ./gradlew myTask should do what you want by default
:myTask
:foo:myTask
:foo:bar:myTask
:baz:myTask

Rake file with Jenkins (Cucumber, watir-webdriver)

I've started with watir and cucumber a while ago and have been trying to run my project with Jenkins. I have a watir Project (watir,cucumber) in C:\project_name. I have rake file in the project also and when I run it in CMD everything goes ok and tests are succesfully executed --> C:\project_name>rake
Rakefile I'm running looks like this.
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.profile = 'default'
end
task :default => :features
I have tried to execute Rake file with Jenkins but unable to make it work. So far what I have done with Jenkins (Running in localhost:8080)
1) Plugins installed eg. cucumber-reports, Jenkins Rake plugin
2) Tried to add New job --> Build a free-style software project
I really don't have idea how to make Rake file to work with Jenkins. I was hoping to get these nice reports (cucumber-reporting) available through Jenkins.
If someone can help me with this it would be more than perfect.

How to run multiple tasks in Ruby?

I have a Capistrano deploy.rb script which has multiple tasks that can be invoked on the command line
cap site1_to_live deploy
cap site2_to_live deploy
(...etc)
I have tried combining these into a single task as follows
task :all_to_live do
site1_to_live
site2_to_live
site3_to_live
end
However, only one of the tasks is executed. How can I get all of them to run?
Define rake task which would group the subtasks. Run this single rake task with capistrano.
This is better because you will be also able to run this grouping task locally.

Resources