Prioratize:
1. see if there is a reasonable chance of escaping. If this is possible see 5, if this is impossible/fails see 2.
2. stand your ground and keep whacking, try and get swallowed and use the tree expansion trick. If this works see 4, if this fails but you are swallowed see 3, if this fails and your not swallowed see 6.
3. cast your rope trick from inside the dragons stomach, making it virtually untargetable for the goblin caster's dispel magic. Rest, get the best spell selection you can get for escaping and try to escape first thing next day. If this works see 5, if this fails see 2, most likely followed by six.
4. (some of) you guys won the encounter, and there was much rejoycing. Hurray!
5. (some of) you guys escape with your lifes. Meh, could be worse.
6. you be dead. so very very dead. maybe you got a rich uncle with acces to some ressurection spells?