iKK
iKK

Reputation: 7012

How to write message to Mattermost using Fastlane?

How do I write a message to Mattermost using Fastlane ?

Below is my trial. I got most from this link.

What is still wrong ? (of course, I replaced the MATTERMOST_WEBHOOK_URL by the actual value that I established in Mattermost).

In the link above, I saw an actions folder with a mattermost.rb file

How do I get this action to work ? What do I need to do inside my Fastfile or anywhere in order to get this to work ?

In fact, running the fastlane send_message lane, I get a success. But unfortunately, nothing is visible in my Mattermost channel.

Inside my Fastfile, I do:

    def send_message_to_mattermost(options)
      unless ENV['MATTERMOST_WEBHOOK_URL'].nil? || ENV['MATTERMOST_WEBHOOK_URL'].empty?
        mattermost(
            pretext: options[:pretext],
            message: options[:msg],
            default_payloads: options[:default_payloads],
            username: 'Fastlane',
            icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
            payload: {},
            attachment_properties: {
                title: options[:title],
                thumb_url: options[:thumb_url],
                fields: [{
                     title: 'Version',
                     value: options[:version_number],
                     short: true
                 },
                 {
                     title: 'Build Number',
                     value: options[:build_number],
                     short: true
                 },
                 {
                     title: 'Built by',
                     value: 'Jenkins',
                     short: true
                 }]
            },
            success: options[:success]
        )
      end
    end

And my Fastlane lane looks like this:

lane :send_message do
    send_message_to_mattermost({
      :version_number => ENV['VERSION_NUMBER'],
      :build_number => ENV["BUILD_NUMBER"],
      :pretext => ENV['MAIN_APP_IDENTIFIER'],
      :title => 'Unsuccessful Build',
      :thumb_url => 'https://support.apple.com/library/content/dam/edam/applecare/images/en_US/iOS/move-to-ios-icon.png',
      :msg => "My message...",
      :default_payloads => [:lane],
      :success => true
   })
end

Is mattermost(...) a standard command in Fastlane ? If not what do I need to do in order to send information to a Mattermost channel from Fastlane ?

Upvotes: 1

Views: 724

Answers (1)

iKK
iKK

Reputation: 7012

I finally found a solution.

What was missing is to set the ENV["MATTERMOST_WEBHOOK_URL"] upfront

before_all do
    ENV["MATTERMOST_WEBHOOK_URL"] = 'https://my_new_webooh_from_mattermost'
end

...and leave the following code intact (i.e. do not replace 'MATTERMOST_WEBHOOK_URL' by anything else - the before_all does the trick...)

    def send_message_to_mattermost(options)
      unless ENV['MATTERMOST_WEBHOOK_URL'].nil? || ENV['MATTERMOST_WEBHOOK_URL'].empty?
        mattermost(
            pretext: options[:pretext],
            message: options[:msg],
            default_payloads: options[:default_payloads],
            username: 'Fastlane',
            icon_url: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
            payload: {},
            attachment_properties: {
                title: options[:title],
                thumb_url: options[:thumb_url],
                fields: [{
                     title: 'Version',
                     value: options[:version_number],
                     short: true
                 },
                 {
                     title: 'Build Number',
                     value: options[:build_number],
                     short: true
                 },
                 {
                     title: 'Built by',
                     value: 'Jenkins',
                     short: true
                 }]
            },
            success: options[:success]
        )
      end
    end

Upvotes: 3

Related Questions